コード例 #1
0
ファイル: MyPage.cs プロジェクト: Raja413/Logger
        public MyPage()
        {
            Resources = new ResourceDictionary();
            Resources.Add("primaryGreen", Color.FromHex("91CA47"));
            Resources.Add("primaryDarkGreen", Color.FromHex("6FA22E"));

            var nav = new NavigationPage(new AAloggerUpSwipeView());
            nav.BarTextColor = Color.Blue;

            MainPage = nav;
        }
コード例 #2
0
		public App ()
		{
			Resources = new ResourceDictionary ();
			Resources.Add ("primaryGreen", Color.FromHex("91CA47"));
			Resources.Add ("primaryDarkGreen", Color.FromHex ("6FA22E"));

			var nav = new NavigationPage (new TodoListPage ());
			nav.BarBackgroundColor = (Color)App.Current.Resources["primaryGreen"];
			nav.BarTextColor = Color.White;

			MainPage = nav;
		}
コード例 #3
0
ファイル: App.cs プロジェクト: Riley19280/Vocab-Master-App
        public App()
        {
            #region Style
            var contentPageStyle = new Style(typeof(ContentPage))
            {
                Setters = {
                new Setter { Property = ContentPage.BackgroundColorProperty, Value = Constants.palette.primary },
                }
            };
            var labelStyle = new Style(typeof(Label))
            {
                Setters = {
                new Setter { Property = Label.TextColorProperty, Value = Constants.palette.primary_text },
                }
            };
            var editorStyle = new Style(typeof(Editor))
            {
                Setters = {
                new Setter { Property = Editor.TextColorProperty, Value = Constants.palette.primary_text },
                new Setter { Property = Editor.BackgroundColorProperty, Value = Constants.palette.primary_light },
                }
            };
            var buttonStyle = new Style(typeof(Button))
            {
                Setters = {
                new Setter { Property = Button.TextColorProperty, Value = Constants.palette.primary_text },
                new Setter { Property = Button.BackgroundColorProperty, Value = Constants.palette.primary_light },
                }
            };
            var switchStyle = new Style(typeof(Switch))
            {
                Setters = {
                new Setter { Property = Switch.BackgroundColorProperty, Value = Constants.palette.primary_light },
                }
            };

            Resources = new ResourceDictionary();
            Resources.Add("contentPageStyle", contentPageStyle);
            Resources.Add("labelStyle", labelStyle);
            Resources.Add("editorStyle", editorStyle);

            #endregion

            // The root page of your application
            mainPage = new NavigationPage(new mainPage())
            {
                BarBackgroundColor = Constants.palette.primary_dark,
                BarTextColor = Constants.palette.icons,
                Title = "VOCAB MASTER",

            };
            MainPage = mainPage;
        }
コード例 #4
0
		public SimpleTriggerPage ()
		{
			var t = new Trigger (typeof(Entry));
			t.Property = Entry.IsFocusedProperty;
			t.Value = true;
			t.Setters.Add (new Setter {Property = Entry.ScaleProperty, Value = 1.5 } );


			var s = new Style (typeof(Entry));
			s.Setters.Add (new Setter { Property = AnchorXProperty, Value = 0} );
			s.Triggers.Add (t);

			Resources = new ResourceDictionary ();
			Resources.Add (s);


			Padding = new Thickness (20, 50, 120, 0);
			Content = new StackLayout { 
				Spacing = 20,
				Children = {
					new Entry { Placeholder = "enter name" },
					new Entry { Placeholder = "enter address" },
					new Entry { Placeholder = "enter city and name" },
				}
			};
		}
コード例 #5
0
        public CustomEasingSwellPage()
        {
            Resources = new ResourceDictionary();

            Resources.Add("customEase", new Easing(t => -6 * t * t + 7 * t));

            InitializeComponent();
        }
コード例 #6
0
 /// <summary>
 /// Makes a shallow copy of the specified ResourceDictionary.
 /// </summary>
 /// <param name="dictionary">ResourceDictionary to copy.</param>
 /// <returns>Copied ResourceDictionary.</returns>
 public static ResourceDictionary ShallowCopy(this ResourceDictionary dictionary)
 {
     ResourceDictionary clone = new ResourceDictionary();
     foreach (object key in dictionary.Keys)
     {
         clone.Add(key, dictionary[key]);
     }
     return clone;
 }
コード例 #7
0
ファイル: App.cs プロジェクト: viniciusoreis/Xamarin02
        public App()
        {
            // The root page of your application
            MainPage = new NavigationPage(new Inicio());

            // Amostra grátis de Styles
            var btnStyle = new Style(typeof(Button));
            btnStyle.Setters.Add(new Setter() { Property = Button.BackgroundColorProperty, Value = Color.Red });
            btnStyle.Setters.Add(new Setter() { Property = Button.TextColorProperty, Value = Color.White });

            Resources = new ResourceDictionary();

            Resources.Add(btnStyle);
        }
コード例 #8
0
        public static ResourceDictionary SelectColor(string status)
        {
            ResourceDictionary r = new ResourceDictionary();

            System.Windows.Media.SolidColorBrush myBrush = null;
            if (string.IsNullOrEmpty(status))
            {
                status = "Pending";
            }
            switch (status)
            {
            case "Passed":
                myBrush = new System.Windows.Media.SolidColorBrush(GingerCore.General.makeColorN("#54A81B"));
                r.Add(status, myBrush);
                break;

            case "Failed":
                myBrush = new System.Windows.Media.SolidColorBrush(GingerCore.General.makeColorN("#E31123"));
                r.Add(status, myBrush);
                break;

            case "Fail":
                myBrush = new System.Windows.Media.SolidColorBrush(GingerCore.General.makeColorN("#E31123"));
                r.Add(status, myBrush);
                break;

            case "Stopped":
                myBrush = new System.Windows.Media.SolidColorBrush(GingerCore.General.makeColorN("#ED5588"));
                r.Add(status, myBrush);
                break;

            case "Pending":
                myBrush = new System.Windows.Media.SolidColorBrush(GingerCore.General.makeColorN("#FF8C00"));
                r.Add(status, myBrush);
                break;

            case "Running":
                myBrush = new System.Windows.Media.SolidColorBrush(GingerCore.General.makeColorN("#800080"));
                r.Add(status, myBrush);
                break;

            default:
                myBrush = new System.Windows.Media.SolidColorBrush(GingerCore.General.makeColorN("#1B3651"));
                r.Add(status, myBrush);
                break;
            }
            return(r);
        }
コード例 #9
0
        public override SpriteTexture GetTexture(uint g)
        {
            if (!ResourceDictionary.TryGetValue(g, out SpriteTexture texture) || texture.IsDisposed)
            {
                ushort[] pixels = GetTextmapTexture((ushort)g, out int size);

                if (pixels == null || pixels.Length == 0)
                {
                    return(null);
                }
                texture = new SpriteTexture(size, size, false);
                texture.SetData(pixels);
                //_usedIndex.Add(g);
                ResourceDictionary.Add(g, texture);
            }

            return(texture);
        }
コード例 #10
0
        public override UOTexture16 GetTexture(uint g)
        {
            if (!ResourceDictionary.TryGetValue(g, out UOTexture16 texture) || texture.IsDisposed)
            {
                ushort[] pixels = GetGumpPixels(g, out int w, out int h);

                if (pixels == null || pixels.Length == 0)
                {
                    return(null);
                }

                texture = new UOTexture16(w, h);
                texture.PushData(pixels);
                ResourceDictionary.Add(g, texture);
            }

            return(texture);
        }
コード例 #11
0
        public override SpriteTexture GetTexture(uint g)
        {
            if (!ResourceDictionary.TryGetValue(g, out SpriteTexture texture) || texture.IsDisposed)
            {
                ushort[] pixels = GetGumpPixels(g, out int w, out int h);

                if (pixels == null || pixels.Length == 0)
                {
                    return(null);
                }

                texture = new SpriteTexture(w, h, false);
                texture.SetDataHitMap16(pixels);
                ResourceDictionary.Add(g, texture);
            }

            return(texture);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: yzddmr6/NetDeserializer
        //生成一个不完整的resourceDictionary xaml 文件
        // 不完整是由于 XmlWrite.Save 的限制,我们可以在其基础上进行更改
        public static void CreateXamlResource()
        {
            var resource = new ResourceDictionary();
            var obj      = new ObjectDataProvider();

            obj.ObjectType = typeof(System.Diagnostics.Process);
            obj.MethodParameters.Add("cmd");
            obj.MethodParameters.Add("/c calc");
            obj.MethodName = "Start";
            resource.Add("powershell", obj);
            var xamlString = XamlWriter.Save(resource);

            using (TextWriter fo = new StreamWriter("./xaml.xml"))
            {
                fo.Write(xamlString);
                fo.Close();
            }
        }
コード例 #13
0
        protected override void Register(Type t)
        {
            if (t.IsInterface)
            {
                return;
            }

            var viewLocatorFactory = new FrameworkElementFactory(typeof(ViewLocator));
            var template           = new DataTemplate(t)
            {
                VisualTree = viewLocatorFactory
            };

//            Application.Current.Dispatcher.InvokeAsync(()=>
            _dictionary.Add(new DataTemplateKey(t), template)
//                )
            ;
        }
コード例 #14
0
        public static ResourceDictionary CreateDynamicDataTemplates([NotNull] ExportProvider exportProvider)
        {
            var dataTemplateResources = new ResourceDictionary();

            var exportMetaData = exportProvider.GetDataTemplateExportsMetadata();

            foreach (var item in exportMetaData)
            {
                var viewModel = item.ViewModel;
                var role      = item.Role;

                var template = CreateTemplate(viewModel, role);

                dataTemplateResources.Add(CreateKey(viewModel, role), template);
            }

            return(dataTemplateResources);
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: Swegrock/Font2Xaml
        private static void SVGFont(string path, List <SolidColorBrush> brushes)
        {
            ResourceDictionary     dictionary = new ResourceDictionary();
            XDocument              doc        = XDocument.Load(path);
            IEnumerable <XElement> elements   = doc.Descendants().Where(x => x.Name.LocalName.Contains("glyph"));
            int brushCount = 0;

            foreach (XElement element in elements)
            {
                SolidColorBrush brush = brushes[brushCount % brushes.Count];
                XAttribute      name  = element.Attribute("glyph-name");
                XAttribute      data  = element.Attribute("d");

                if (name == null || data == null)
                {
                    continue;
                }
                GeometryDrawing drawing = new GeometryDrawing
                {
                    Brush    = brush,
                    Geometry = Geometry.Combine(Geometry.Empty, Geometry.Parse(data.Value), GeometryCombineMode.Union, new ScaleTransform(1, -1))
                };

                DrawingImage drawingImage = new DrawingImage(drawing);
                dictionary.Add(name.Value, drawingImage);
                brushCount++;
            }

            Console.WriteLine($"Successfully converted {dictionary.Count} characters");
            if (brushCount < brushes.Count)
            {
                Console.WriteLine($"Too many colors were supplied. {brushes.Count - brushCount} colors were ignored");
            }

            using (XmlWriter writer = XmlWriter.Create(Path.Combine(Path.GetDirectoryName(path), $"{Path.GetFileNameWithoutExtension(path)}.xaml"),
                                                       new XmlWriterSettings {
                Indent = true
            }))
            {
                XamlDesignerSerializationManager sm = new XamlDesignerSerializationManager(writer);
                sm.XamlWriterMode = XamlWriterMode.Expression;
                XamlWriter.Save(dictionary, writer);
            }
        }
コード例 #16
0
        private void AddEntries(ResourceDictionary source, ResourceDictionary dest, HashSet <string> dics)
        {
            var localPath = source.Source?.LocalPath;

            if (localPath != null && dics.Contains(localPath))
            {
                return;
            }

            dics.Add(localPath);

            foreach (var md in source.MergedDictionaries)
            {
                AddEntries(md, dest, dics);
            }

            foreach (DictionaryEntry de in source)
            {
                var key = de.Key;
                if (dest.Contains(key))
                {
                    continue;
                }

                object value       = de.Value;
                var    colorThemes = GetColorThemes();
                if (colorThemes != null && colorThemes.Length > 0)
                {
                    //TODO: optimise Color Theme code
                    var colorEntry = colorThemes
                                     .SelectMany(x => x.Entries)
                                     .OfType <ColorEntry>()
                                     .SingleOrDefault(x => Equals(x.ResourceKey, key));

                    if (colorEntry != null)
                    {
                        value = colorEntry.ToColor();
                    }
                }

                _dispatcher.Invoke(() => dest.Add(key, value));
            }
        }
コード例 #17
0
 /// <summary>
 /// Assemble all DataTemplates for different entities in one ResourceDictionary.
 /// </summary>
 private static void AssembleAllTemplates()
 {
     foreach (string resourceDictionaryName in resourceDictionaryNames)
     {
         ResourceDictionary newDict = Api.Client.UI.LoadResourceDictionary(
             "UI/Controls/Game/CNEImenu/Data/EntityTemplates/" + resourceDictionaryName);
         if (newDict != null)
         {
             foreach (DictionaryEntry entry in newDict)
             {
                 AllEntityTemplatesResourceDictionary.Add(entry.Key, entry.Value);
             }
         }
         else
         {
             Api.Logger.Error("CNEI: Can not load template " + resourceDictionaryName);
         }
     }
 }
コード例 #18
0
 /// <summary>
 /// Assemble all DataTemplates for different entities in one ResourceDictionary.
 /// </summary>
 private static void AssembleAllTemplates()
 {
     foreach (string resourceDictionaryName in resourceDictionaryPaths)
     {
         ResourceDictionary newDict = Api.Client.UI.LoadResourceDictionary(
             "UI/CNEI/Data/EntityTemplates/" + resourceDictionaryName);
         if (newDict != null)
         {
             foreach (var key in newDict.Keys)
             {
                 AllEntityTemplatesResourceDictionary.Add(key, newDict[key]);
             }
         }
         else
         {
             Api.Logger.Error("CNEI: Can not load template " + resourceDictionaryName);
         }
     }
 }
コード例 #19
0
ファイル: ParserDesign.cs プロジェクト: dlebansais/Wrist
        private void AddDictionaryContent(IParsingSourceStream sourceStream, ResourceDictionary wrapped, ResourceDictionary dictionary)
        {
            foreach (object Key in dictionary.Keys)
            {
                if (!wrapped.Contains(Key))
                {
                    wrapped.Add(Key, dictionary[Key]);
                }
                else
                {
                    throw new ParsingException(92, sourceStream, $"Key '{Key}' found multiple times.");
                }
            }

            foreach (ResourceDictionary Item in dictionary.MergedDictionaries)
            {
                AddDictionaryContent(sourceStream, wrapped, Item);
            }
        }
コード例 #20
0
        private ResourceDictionaryCollection createResourceDictionary(List <System.Drawing.Color> col)
        {
            ResourceDictionaryCollection palette = new ResourceDictionaryCollection();


            for (int i = 0; i < col.Count; i++)
            {
                ResourceDictionary   PalleteColors = new ResourceDictionary();
                System.Drawing.Color color         = col[i];
                SolidColorBrush      active        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(color.R, color.G, color.B));
                string name = "brush" + i;
                PalleteColors.Add(name, active);
                palette.Add(PalleteColors);
            }



            return(palette);
        }
コード例 #21
0
        public void When_Default_Theme_Dictionary_Is_Cached()
        {
            var defaultDictionary = new ResourceDictionary();

            defaultDictionary.Add("TestKey", "TestValueFromDefaultDictionary");

            var dictionary = new ResourceDictionary();

            dictionary.ThemeDictionaries.Add("Default", defaultDictionary);
            Assert.IsTrue(dictionary.TryGetValue("TestKey", out var testValue));
            Assert.AreEqual("TestValueFromDefaultDictionary", testValue);

            var lightDictionary = new ResourceDictionary();

            lightDictionary.Add("TestKey", "TestValueFromLightDictionary");
            dictionary.ThemeDictionaries.Add("Light", lightDictionary);
            Assert.IsTrue(dictionary.TryGetValue("TestKey", out testValue));
            Assert.AreEqual("TestValueFromLightDictionary", testValue);
        }
コード例 #22
0
        private static void AdjustResourceColor(ResourceDictionary resources, string sourceKey, string targetKey, float factor)
        {
            if (!resources.Contains(sourceKey))
            {
                return;
            }

            var sourceColor = (Color)resources[sourceKey];
            var targetColor = sourceColor.ToBrightened(factor);

            if (resources.Contains(targetKey))
            {
                resources[targetKey] = targetColor;
            }
            else
            {
                resources.Add(targetKey, targetColor);
            }
        }
コード例 #23
0
		public ImplicitStylesPageCS ()
		{
			var entryStyle = new Style (typeof(Entry)) {
				Setters = {
					new Setter { 
						Property = View.HorizontalOptionsProperty,
						Value = LayoutOptions.Fill
					},
					new Setter {
						Property = View.VerticalOptionsProperty,
						Value = LayoutOptions.CenterAndExpand
					},
					new Setter {
						Property = VisualElement.BackgroundColorProperty,
						Value = Color.Yellow
					},
					new Setter {
						Property = Entry.FontAttributesProperty,
						Value = FontAttributes.Italic
					},
					new Setter {
						Property = Entry.TextColorProperty,
						Value = Color.Blue
					} 
				}	
			};

			Title = "Implicit";
			Icon = "csharp.png";
			Padding = new Thickness (0, 20, 0, 0);
			Resources = new ResourceDictionary ();
			Resources.Add (entryStyle);

			Content = new StackLayout { 
				Children = {
					new Entry { Text = "These entries" },
					new Entry { Text = "are demonstrating" },
					new Entry { Text = "implicit styles," },
					new Entry { Text = "and an implicit style override", BackgroundColor = Color.Lime, TextColor = Color.Red },
					new CustomEntry  { Text = "Subclassed Entry is not receiving the style" }
				}
			};
		}
コード例 #24
0
        public void When_Theme_Dictionary_Is_Cached_Then_Add_And_Remove_Theme()
        {
            var dictionary = new ResourceDictionary();

            dictionary.TryGetValue("TestKey", out _);             // This causes _activeThemeDictionary to be cached.

            var lightTheme = new ResourceDictionary();

            lightTheme.Add("TestKey", "TestValue");
            dictionary.ThemeDictionaries.Add("Light", lightTheme);             // Cached value is no longer valid due to adding theme.

            // Make sure the cache is updated.
            Assert.IsTrue(dictionary.TryGetValue("TestKey", out var testValue));
            Assert.AreEqual("TestValue", testValue);

            Assert.IsTrue(dictionary.ThemeDictionaries.Remove("Light"));             // Cached value is no longer valid due to removing theme.

            Assert.IsFalse(dictionary.TryGetValue("TestKey", out _));
        }
コード例 #25
0
        public void TemplateFindDefaultTest()
        {
            string text = @"
            <ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' TargetType='{x:Type Control}'>
                <FrameworkElement/>
            </ControlTemplate>";

            ControlTemplate controlTemplate = XamlLoader.Load(XamlParser.Parse(text)) as ControlTemplate;

            ResourceDictionary resources = new ResourceDictionary();

            resources.Add(new TemplateKey(typeof(Control)), controlTemplate);

            Control control = new Control();

            control.Resources = resources;

            Assert.AreEqual(controlTemplate, control.Template);
        }
コード例 #26
0
        private static List <ResourceDictionary> CreateOcticonsResources()
        {
            var resourceDictionary = new ResourceDictionary();

            var style = new Style(typeof(PackIconOcticonsControl));

            style.Setters.Add(new Setter {
                Property = FrameworkElement.HeightProperty, Value = 16.0
            });
            style.Setters.Add(new Setter {
                Property = FrameworkElement.WidthProperty, Value = 16.0
            });
            style.Setters.Add(new Setter {
                Property = Control.PaddingProperty, Value = new Thickness(0.0)
            });
            style.Setters.Add(new Setter {
                Property = FrameworkElement.FlowDirectionProperty, Value = FlowDirection.LeftToRight
            });
            style.Setters.Add(new Setter {
                Property = FrameworkElement.HorizontalAlignmentProperty, Value = HorizontalAlignment.Center
            });
            style.Setters.Add(new Setter {
                Property = FrameworkElement.VerticalAlignmentProperty, Value = VerticalAlignment.Center
            });
            style.Setters.Add(new Setter {
                Property = Control.IsTabStopProperty, Value = false
            });
            style.Setters.Add(new Setter {
                Property = UIElement.SnapsToDevicePixelsProperty, Value = false
            });
            style.Setters.Add(new Setter {
                Property = FrameworkElement.UseLayoutRoundingProperty, Value = false
            });
            style.Setters.Add(new Setter {
                Property = Control.TemplateProperty, Value = GetIconTemplate()
            });

            resourceDictionary.Add(typeof(PackIconOcticonsControl), style);

            return(new List <ResourceDictionary> {
                resourceDictionary
            });
        }
コード例 #27
0
        private void ApplyResourceDictionaryEntries(ResourceDictionary oldRd, ResourceDictionary newRd)
        {
            foreach (var newRdMergedDictionary in newRd.MergedDictionaries)
            {
                this.ApplyResourceDictionaryEntries(oldRd, newRdMergedDictionary);
            }

#pragma warning disable CS8605
            foreach (DictionaryEntry dictionaryEntry in newRd)
            {
                if (oldRd.Contains(dictionaryEntry.Key))
                {
                    oldRd.Remove(dictionaryEntry.Key);
                }

                oldRd.Add(dictionaryEntry.Key, dictionaryEntry.Value);
            }
#pragma warning restore CS8605
        }
コード例 #28
0
ファイル: ResourceHelper.cs プロジェクト: razcandy/IMCTest
        // Events & Handlers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        // Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        public static void Load()
        {
            var rd = new ResourceDictionary();

            rd.Add(ButtonDefaultStyle);
            rd.Add(EntryDefaultStyle);
            rd.Add(FrameDefaultStyle);
            rd.Add(LabelDefaultStyle);
            rd.Add(PickerDefaultStyle);

            rd.Add(nameof(LabelHeaderStyle), LabelHeaderStyle);

            App.Current.Resources = rd;
        }
コード例 #29
0
        /// <summary>
        /// 该算法精确到setter,可以保留原始所有样式的同时,替换或者补充后来加的样式里面的setter
        /// </summary>
        /// <param name="source"></param>
        /// <param name="append"></param>
        private static void MergeStyles(ResourceDictionary source, ResourceDictionary append)
        {
            foreach (string key in append.Keys)
            {
                //检索追加的资源中的每一个style
                var targetStyle    = append[key] as Style;
                var result         = FindStyle(source, key);
                var sourceStyle    = result.style;
                var sourceResource = result.resource;
                if (result.style == null)
                {
                    //原始资源中没有,那么直接追加
                    source.Add(key, targetStyle);
                }
                else
                {
                    //原始资源中有,那么合并setter
                    Style style = new Style(sourceStyle.TargetType, sourceStyle.BasedOn);
                    foreach (var sourceSetter in sourceStyle.Setters)
                    {
                        style.Setters.Add(sourceSetter);
                    }

                    foreach (Setter targetSetter in targetStyle.Setters)
                    {
                        var same = style.Setters.FirstOrDefault((t) =>
                        {
                            return((t as Setter).Property.Name.EqualsIgnoreCase(targetSetter.Property.Name));
                        }) as Setter;
                        if (same != null)
                        {
                            style.Setters.Remove(same);
                        }
                        style.Setters.Add(targetSetter);
                    }

                    //移除老的style,将新生成的style追加到资源中
                    sourceResource.Remove(sourceStyle);
                    sourceResource.Add(key, style);
                }
            }
        }
コード例 #30
0
        private void ApplyCaptionTheme(ResourceDictionary targetDictionary, ResourceDictionary sourceDictionary, Brush background)
        {
            var defaultDictionary = new ResourceDictionary {
                Source = new Uri(_defaultCaptionThemeUriString, UriKind.Relative)
            };

            foreach (var key in defaultDictionary.Keys)
            {
                Color?newColor = null;

                if (sourceDictionary.Contains(key))
                {
                    var sourceValue = sourceDictionary[key];
                    if (sourceValue is Color)
                    {
                        newColor = (Color)sourceValue;

                        if (BlendsCaptionButtonVisualStyle)
                        {
                            var solid = background as SolidColorBrush;
                            if (solid != null)
                            {
                                newColor = newColor.Value.ToBlended(solid.Color.ToOpaque(), (double)(255 - newColor.Value.A) / 255D * 100D);
                            }
                        }
                    }
                }

                object newValue = newColor ?? defaultDictionary[key];

                if (!targetDictionary.Contains(key))
                {
                    // Add key and value.
                    targetDictionary.Add(key, newValue);
                }
                else
                {
                    // Update value.
                    targetDictionary[key] = newValue;
                }
            }
        }
コード例 #31
0
ファイル: Program.cs プロジェクト: sebastiandymel/SEDY
        private static void GenerateColorResources(int count)
        {
            var fileName = "Colors.xaml";

            var resourceDictionary = new ResourceDictionary();

            for (int i = 0; i < count; i++)
            {
                resourceDictionary.Add(
                    $"ThisIsSomeKey{i}",
                    Color.FromArgb(255, (byte)rnd.Next(0, 255), (byte)rnd.Next(0, 255), (byte)rnd.Next(0, 255))
                    );
            }

            var output = XamlWriter.Save(resourceDictionary);

            File.WriteAllText(fileName, output);

            Console.WriteLine("Colors.xaml generated");
        }
コード例 #32
0
        static StatementLabel()
        {
            resourceDictionary = new ResourceDictionary();

            Style style = new Style(typeof(TextBlock));

            style.Setters.Add(new Setter(TextBlock.FontSizeProperty, 12.0));
            style.Setters.Add(new Setter(TextBlock.FontWeightProperty, FontWeights.Bold));
            style.Setters.Add(new Setter(TextBlock.FontFamilyProperty, new FontFamily("Helvetica")));
            style.Setters.Add(new Setter(TextBlock.ForegroundProperty, Brushes.Black));
            style.Setters.Add(new Setter(TextBlock.WidthProperty, 80.0));
            //style.Setters.Add(new Setter(TextBlock.HeightProperty,40.0));
            //style.Setters.Add(new Setter(TextBlock.PaddingProperty,new Thickness(10)));
            style.Setters.Add(new Setter(TextBlock.TextWrappingProperty, TextWrapping.Wrap));
            style.Setters.Add(new Setter(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center));
            style.Setters.Add(new Setter(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center));
            style.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));

            resourceDictionary.Add(style.TargetType, style);
        }
コード例 #33
0
        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var myResources = new ResourceDictionary();
            var style       = new Style(typeof(MetroProgressBar));

            style.Setters.Add(new Setter(MetroProgressBar.EllipseDiameterProperty, 30d));

            myResources.Add(typeof(MetroProgressBar), style);

            var ok = await this.ShowProgressAsync("", "", settings : new MetroDialogSettings
            {
                DialogMessageFontSize    = 12,
                CustomResourceDictionary = myResources,
                AnimateShow = false,
                AnimateHide = false,
                ColorScheme = this.MetroDialogOptions.ColorScheme,
            });

            ok.SetIndeterminate();
        }
コード例 #34
0
        public void AddingResourceInMergedRDTriggersValueChanged()
        {
            var rd0 = new ResourceDictionary();
            var rd  = new ResourceDictionary {
                MergedDictionaries =
                {
                    rd0
                }
            };

            var label = new Label {
                Resources = rd,
            };

            label.SetDynamicResource(Label.TextProperty, "foo");
            Assert.That(label.Text, Is.EqualTo(Label.TextProperty.DefaultValue));

            rd0.Add("foo", "Foo");
            Assert.That(label.Text, Is.EqualTo("Foo"));
        }
コード例 #35
0
        /// <summary>
        /// Get resources recursive from dictionary and merged dictionaries
        /// </summary>
        private static void LoadResourcesRecursive(ResourceDictionary targetResources, ResourceDictionary sourceResources)
        {
            if (sourceResources.MergedDictionaries != null)
            {
                foreach (ResourceDictionary resourceDictionary in sourceResources.MergedDictionaries)
                {
                    LoadResourcesRecursive(targetResources, resourceDictionary);
                }
            }

            foreach (var resource in sourceResources)
            {
                if (targetResources.ContainsKey(resource.Key))
                {
                    targetResources.Remove(resource.Key);
                }

                targetResources.Add(resource.Key, resource.Value);
            }
        }
コード例 #36
0
        public void StyleFindDefaultTest()
        {
            Style style = new Style {
                TargetType = typeof(Control)
            };

            style.Setters.Add(new Setter {
                Property = new DependencyPropertyPathElement(FrameworkElement.WidthProperty), Value = 100
            });

            ResourceDictionary resources = new ResourceDictionary();

            resources.Add(new StyleKey(typeof(Control)), style);

            Control control = new Control();

            control.Resources = resources;

            Assert.AreEqual(style, control.Style);
        }
コード例 #37
0
ファイル: Util.cs プロジェクト: skive-college/AspitPlanner
        public static System.Collections.ObjectModel.Collection <ResourceDictionary> MakePalette(List <ChartValue> list)
        {
            System.Collections.ObjectModel.Collection <ResourceDictionary> palette = new System.Collections.ObjectModel.Collection <ResourceDictionary>();
            foreach (ChartValue item in list)
            {
                ResourceDictionary rd = new ResourceDictionary();
                Style           style = new Style(typeof(Control));
                SolidColorBrush brush = null;
                switch (item.ID)
                {
                case 1: brush = new SolidColorBrush(Colors.LightBlue); break;

                case 2: brush = new SolidColorBrush(Colors.DarkOrange); break;

                case 3: brush = new SolidColorBrush(Colors.Red); break;

                case 4: brush = new SolidColorBrush(Colors.Green); break;

                case 5: brush = new SolidColorBrush(Colors.LightGreen); break;

                case 6: brush = new SolidColorBrush(Colors.DarkKhaki); break;

                case 7: brush = new SolidColorBrush(Colors.Yellow); break;

                case 9: brush = new SolidColorBrush(Colors.OrangeRed); break;

                case 10: brush = new SolidColorBrush(Colors.Aquamarine); break;

                case 11: brush = new SolidColorBrush(Colors.Red); break;

                default: brush = new SolidColorBrush(Colors.Black); break;
                }
                style.Setters.Add(new Setter()
                {
                    Property = Control.BackgroundProperty, Value = brush
                });
                rd.Add("DataPointStyle", style);
                palette.Add(rd);
            }
            return(palette);
        }
コード例 #38
0
        public override UOTexture GetTexture(uint g)
        {
            if (!ResourceDictionary.TryGetValue(g, out UOTexture texture) || texture.IsDisposed)
            {
                ushort[] pixels = GetTextmapTexture((ushort)g, out int size);

                if (pixels == null || pixels.Length == 0)
                {
                    return(null);
                }

                texture = new UOTexture16(size, size);
                texture.SetData(pixels);
                //_usedIndex.Add(g);
                ResourceDictionary.Add(g, texture);
            }
            //else
            //    texture.Ticks = Time.Ticks + 3000;

            return(texture);
        }
コード例 #39
0
        private static void Clone(ResourceDictionary source, ResourceDictionary target)
        {
            foreach (var resourceKeyValue in source)
            {
                target.Add(resourceKeyValue.Key, resourceKeyValue.Value);
            }

            foreach (var dictionary in source.MergedDictionaries)
            {
                var clone = new ResourceDictionary();
                Clone(dictionary, clone);
                target.MergedDictionaries.Add(clone);
            }

            foreach (var dictionaryKeyValue in source.ThemeDictionaries)
            {
                var clone = new ResourceDictionary();
                Clone((ResourceDictionary)dictionaryKeyValue.Value, clone);
                target.ThemeDictionaries.Add(dictionaryKeyValue.Key, clone);
            }
        }
		public DynamicStylesInheritancePageCS ()
		{
			Title = "Dynamic Inheritance";
			Icon = "csharp.png";
			Padding = new Thickness (0, 20, 0, 0);

			var baseStyle = new Style (typeof(View)) {
				Setters = {
					new Setter {
						Property = View.VerticalOptionsProperty,
						Value = LayoutOptions.CenterAndExpand
					}
				}
			};

			var blueSearchBarStyle = new Style (typeof(SearchBar)) {
				BasedOn = baseStyle,
				Setters = {
					new Setter {
						Property = SearchBar.FontAttributesProperty,
						Value = FontAttributes.Italic
					},
					new Setter {
						Property = SearchBar.TextColorProperty,
						Value = Color.Blue
					} 
				}	
			};

			var greenSearchBarStyle = new Style (typeof(SearchBar)) {
				Setters = {
					new Setter {
						Property = SearchBar.FontAttributesProperty,
						Value = FontAttributes.None
					},
					new Setter {
						Property = SearchBar.TextColorProperty,
						Value = Color.Green
					}
				}	
			};

			var tealSearchBarStyle = new Style (typeof(SearchBar)) {
				BaseResourceKey = "searchBarStyle",
				Setters = {
					new Setter {
						Property = VisualElement.BackgroundColorProperty,
						Value = Color.Teal
					},
					new Setter { 
						Property = SearchBar.CancelButtonColorProperty,
						Value = Color.White
					}
				}
			};

			var buttonStyle = new Style (typeof(Button)) {
				BasedOn = baseStyle,
				Setters = {
					new Setter {
						Property = Button.FontSizeProperty,
						Value = Device.GetNamedSize (NamedSize.Large, typeof(Button))
					},
					new Setter {
						Property = Button.TextColorProperty,
						Value = Color.Red
					} 
				}	
			};

			var button = new Button { Text = "Change Style", Style = buttonStyle };
			button.Clicked += OnButtonClicked;

			Resources = new ResourceDictionary ();
			Resources.Add ("blueSearchBarStyle", blueSearchBarStyle);
			Resources.Add ("greenSearchBarStyle", greenSearchBarStyle);
			Resources ["searchBarStyle"] = Resources ["blueSearchBarStyle"];

			Content = new StackLayout { 
				Children = {
					new SearchBar { Text = "These SearchBar controls", Style = tealSearchBarStyle },
					new SearchBar { Text = "are demonstrating", Style = tealSearchBarStyle },
					new SearchBar { Text = "dynamic style inheritance, ", Style = tealSearchBarStyle },
					new SearchBar { Text = "but this isn't dynamic", Style = (Style)Resources ["blueSearchBarStyle"] },
					button
				}
			};
		}
コード例 #41
0
		public void RenameResources() {
			if (resourceManagerType == null && componentResourceManagerType == null)
				return;

			var rsrcDict = new ResourceDictionary();
			foreach (var resource in module.Resources)
				rsrcDict.Add(resource);

			if (module.Assembly != null)
				Rename(rsrcDict, "", module.Assembly.Name + ".g");

			foreach (var type in callsResourceManager.Keys)
				Rename(rsrcDict, type);

			if (rsrcDict.Count != 0) {
				foreach (var type in module.GetTypes()) {
					if (rsrcDict.Count == 0)
						break;
					if (!IsWinFormType(type))
						continue;
					Rename(rsrcDict, type);
				}
			}

			if (rsrcDict.Count != 0) {
				foreach (var type in module.GetTypes()) {
					if (rsrcDict.Count == 0)
						break;
					Rename(rsrcDict, type);
				}
			}

			if (rsrcDict.Count != 0)
				Logger.e("Couldn't restore all renamed resource names");
		}
コード例 #42
0
		public DynamicStylesPageCS ()
		{
			Title = "Dynamic";
			Icon = "csharp.png";
			Padding = new Thickness (0, 20, 0, 0);

			var baseStyle = new Style (typeof(View)) {
				Setters = {
					new Setter {
						Property = View.VerticalOptionsProperty,
						Value = LayoutOptions.CenterAndExpand
					}
				}
			};

			var blueSearchBarStyle = new Style (typeof(SearchBar)) {
				BasedOn = baseStyle,
				Setters = {
					new Setter {
						Property = SearchBar.FontAttributesProperty,
						Value = FontAttributes.Italic
					},
					new Setter {
						Property = SearchBar.PlaceholderColorProperty,
						Value = Color.Blue
					} 
				}	
			};

			var greenSearchBarStyle = new Style (typeof(SearchBar)) {
				Setters = {
					new Setter {
						Property = SearchBar.FontAttributesProperty,
						Value = FontAttributes.None
					},
					new Setter {
						Property = SearchBar.PlaceholderColorProperty,
						Value = Color.Green
					}
				}	
			};

			var buttonStyle = new Style (typeof(Button)) {
				BasedOn = baseStyle,
				Setters = {
					new Setter {
						Property = Button.FontSizeProperty,
						Value = Device.GetNamedSize (NamedSize.Large, typeof(Button))
					},
					new Setter {
						Property = Button.TextColorProperty,
						Value = Color.Red
					} 
				}	
			};					

			var searchBar1 = new SearchBar { Placeholder = "These SearchBar controls" };
			searchBar1.SetDynamicResource (VisualElement.StyleProperty, "searchBarStyle");
			var searchBar2 = new SearchBar { Placeholder = "are demonstrating" };
			searchBar2.SetDynamicResource (VisualElement.StyleProperty, "searchBarStyle");
			var searchBar3 = new SearchBar { Placeholder = "dynamic styles, " };
			searchBar3.SetDynamicResource (VisualElement.StyleProperty, "searchBarStyle");
			var searchBar4 = new SearchBar { Placeholder = "but this isn't dynamic", Style = blueSearchBarStyle };

			var button = new Button { Text = "Change Style", Style = buttonStyle };
			button.Clicked += OnButtonClicked;

			Resources = new ResourceDictionary ();
			Resources.Add ("blueSearchBarStyle", blueSearchBarStyle);
			Resources.Add ("greenSearchBarStyle", greenSearchBarStyle);
			Resources ["searchBarStyle"] = Resources ["blueSearchBarStyle"];

			Content = new StackLayout { 
				Children = {
					searchBar1,
					searchBar2,
					searchBar3,
					searchBar4,
					button
				}
			};
		}
コード例 #43
0
ファイル: Splash.xaml.cs プロジェクト: noriike/xaml-106136
        public static void SetupTheme(bool reload = true)
        {
            var _ColorString = StorageHelper.GetSetting(Contracts.Settings.PrimaryColor, Contracts.Settings.DefaultColor);

            Uri _Path = null;
            if (_ColorString.Equals(Windows.UI.Colors.Red.ToString()))
                _Path = new Uri("ms-appx:/Styles/CustomStyles.Red.xaml");
            else if (_ColorString.Equals(Windows.UI.Colors.Green.ToString()))
                _Path = new Uri("ms-appx:/Styles/CustomStyles.Green.xaml");
            else if (_ColorString.Equals(Windows.UI.Colors.Blue.ToString()))
                _Path = new Uri("ms-appx:/Styles/CustomStyles.Blue.xaml");
            else if (_ColorString.Equals(Windows.UI.Colors.Orange.ToString()))
                _Path = new Uri("ms-appx:/Styles/CustomStyles.Orange.xaml");

            var _Standard = new ResourceDictionary { Source = new Uri("ms-appx:/Styles/StandardStyles.xaml") };
            var _Custom = new ResourceDictionary { Source = _Path };
            var _Main = new ResourceDictionary { MergedDictionaries = { _Standard, _Custom } };
            foreach (var item in App.Current.Resources)
            {
                if (!_Main.ContainsKey(item.Key))
                    _Main.Add(item);
            }
            App.Current.Resources = _Main;

            // refresh the style immediately
            if (reload)
                Services.Navigation.Reload();
        }
コード例 #44
0
 public static void Update(ResourceDictionary resources)
 {
     resources.Add("LocalizedStrings", new LocalizedStrings());
     resources.Add("ViewModelLocator", new ViewModelLocator(ServiceLocator.Resolve<IContainer>()));
     resources.Add("DeviceSpecificsLocator", new DeviceSpecificsLocator(ServiceLocator.Resolve<IContainer>()));
 }
コード例 #45
0
ファイル: App.cs プロジェクト: Railgun-it/autoresolve-app
        private void InitGlobalStyles()
        {
            Resources = new ResourceDictionary();

            var masterDetailstyle = new Style(typeof(MasterDetailPage))
            {

                Setters =
                {
                    new Setter { Property = MasterDetailPage.BackgroundColorProperty, Value = Color.White },
                    new Setter { Property = MasterDetailPage.BackgroundColorProperty, Value = Color.White }

                }
            };
            Resources.Add(masterDetailstyle);
            //button
            var buttonStyle = new Style(typeof(Button))
            {
                Setters =
                {
                    new Setter {Property = Button.TextColorProperty, Value = Color.White},
                                        new Setter {Property = Button.BackgroundColorProperty, Value = Color.FromRgb(254,39,61)}

                }
            };
            Resources.Add(buttonStyle);

            //nav page - can't superclass
            var navPageStyle = new Style(typeof(NavigationPage))
            {
                Setters =
                {
                    new Setter {Property = NavigationPage.BackButtonTitleProperty, Value = Color.Black},
                    new Setter {Property = NavigationPage.BarTextColorProperty, Value = Color.FromRgb(254,39,61)},
                    new Setter {Property = NavigationPage.TitleProperty, Value = Color.Black},
                       new Setter {Property = NavigationPage.TitleProperty, Value = TextAlignment.End},
                    new Setter {Property = NavigationPage.BackgroundColorProperty, Value = Color.White}
                }
            };
            Resources.Add(navPageStyle);
            //Base64EncodedContent page
            var contentPageSTyle = new Style(typeof(ContentPage))
            {
                Setters =
                {
                    new Setter {Property = ContentPage.BackgroundColorProperty, Value = Color.White},
                       new Setter {Property = ContentPage.TitleProperty, Value = Color.Black}


                }
            };
            Resources.Add(contentPageSTyle);


            var labelStyle = new Style(typeof(Label))
            {
                Setters =
                {
                    new Setter {Property = Label.BackgroundColorProperty, Value = Color.White},
                    new Setter {Property = Label.TextColorProperty, Value = Color.Black},
                     new Setter {Property = Label.FontSizeProperty, Value = Font.SystemFontOfSize(NamedSize.Medium)}
                }
            };
            Resources.Add(labelStyle);


            var extendedLabelStyle = new Style(typeof(ExtendedLabel))
            {
                Setters =
                {
                    new Setter {Property = ExtendedLabel.BackgroundColorProperty, Value = Color.White},
                    new Setter {Property = ExtendedLabel.TextColorProperty, Value = Color.Black},
                     new Setter {Property = ExtendedLabel.FontSizeProperty, Value = Font.SystemFontOfSize(NamedSize.Medium)},
                     new Setter {Property = ExtendedLabel.IsUnderlineProperty, Value = true},


                }
            };
            Resources.Add(extendedLabelStyle);

            var entryStyle = new Style(typeof(Entry))
            {
                Setters =
                {
                    new Setter {Property = Entry.BackgroundColorProperty, Value = Color.White},
                    new Setter {Property = Entry.TextColorProperty, Value = Color.Black},
                      new Setter {Property = Entry.OpacityProperty, Value = 0.5}
                }
            };
            Resources.Add(entryStyle);

            var extendedEntry = new Style(typeof(ExtendedEntry))
            {
                Setters =
                {
                    new Setter {Property = ExtendedEntry.BackgroundColorProperty, Value = Color.White},
                    new Setter {Property = ExtendedEntry.TextColorProperty, Value = Color.Black},
                      new Setter {Property = ExtendedEntry.PlaceholderTextColorProperty, Value = Color.Purple},

                }
            };
            Resources.Add(extendedEntry);

        }
コード例 #46
0
ファイル: CNE.cs プロジェクト: marciopmm/CNE
		private void SetStyles()
		{
			Resources = new ResourceDictionary ();

			var contentStyle = new Style (typeof(ContentPage)) {
				Setters = {
					new Setter {
						Property = ContentPage.BackgroundColorProperty,
						Value = Color.White
					}
				}
			};
			Resources.Add (contentStyle);

			var entryStyle = new Style (typeof(Entry)) {
				Setters = {
					new Setter {
						Property = Entry.BackgroundColorProperty,
						Value = Color.FromHex("EEEEEE")
					},
					new Setter {
						Property = Entry.TextColorProperty,
						Value = Color.FromHex("333333")
					},
					new Setter {
						Property = Entry.HorizontalOptionsProperty,
						Value = LayoutOptions.FillAndExpand
					},
					new Setter {
						Property = Entry.VerticalOptionsProperty,
						Value = LayoutOptions.CenterAndExpand
					}
				}
			};
			Resources.Add (entryStyle);

			var editorStyle = new Style (typeof(Editor)) {
				Setters = {
					new Setter {
						Property = Editor.BackgroundColorProperty,
						Value = Color.FromHex("EEEEEE")
					},
					new Setter {
						Property = Editor.TextColorProperty,
						Value = Color.FromHex("333333")
					},
					new Setter {
						Property = Editor.HorizontalOptionsProperty,
						Value = LayoutOptions.FillAndExpand
					},
					new Setter {
						Property = Editor.VerticalOptionsProperty,
						Value = LayoutOptions.FillAndExpand
					}
				}
			};
			Resources.Add (editorStyle);

			var pickerStyle = new Style (typeof(Picker)) {
				Setters = {
					new Setter {
						Property = Picker.BackgroundColorProperty,
						Value = Color.FromHex("EEEEEE")
					},
					new Setter {
						Property = Picker.HorizontalOptionsProperty,
						Value = LayoutOptions.FillAndExpand
					},
					new Setter {
						Property = Picker.VerticalOptionsProperty,
						Value = LayoutOptions.CenterAndExpand
					}
				}
			};
			Resources.Add (pickerStyle);

			var datePickerStyle = new Style (typeof(DatePicker)) {
				Setters = {
					new Setter {
						Property = DatePicker.BackgroundColorProperty,
						Value = Color.FromHex("EEEEEE")
					},
					new Setter {
						Property = DatePicker.HorizontalOptionsProperty,
						Value = LayoutOptions.FillAndExpand
					},
					new Setter {
						Property = DatePicker.VerticalOptionsProperty,
						Value = LayoutOptions.CenterAndExpand
					}
				}
			};
			Resources.Add (datePickerStyle);

			var buttonStyle = new Style (typeof(Button)) {
				Setters = {
					new Setter { 
						Property = Button.BackgroundColorProperty, 
						Value = Color.FromHex("DDDDDD")
					},
					new Setter {
						Property = Button.BorderRadiusProperty,
						Value = 5
					},
					new Setter {
						Property = Button.BorderWidthProperty,
						Value = 2
					},
					new Setter {
						Property = Button.BorderColorProperty,
						Value = Color.FromHex("444444")
					},
					new Setter {
						Property = Button.TextColorProperty,
						Value = Color.FromHex("333333")
					},
					new Setter {
						Property = Button.HorizontalOptionsProperty,
						Value = LayoutOptions.FillAndExpand
					},
					new Setter {
						Property = Button.VerticalOptionsProperty,
						Value = LayoutOptions.CenterAndExpand
					}
				}
			};
			Resources.Add (buttonStyle);

			var labelStyle = new Style (typeof(Label)) {
				Setters = {
					new Setter {
						Property = Label.TextColorProperty,
						Value = Color.FromHex ("333333")
					}
				}
			};
			Resources.Add (labelStyle);

		}