コード例 #1
0
 public AdvancedEditWindow(a_animes AnimeToChange, AniMoDBEntities db)
 {
     ResourceDictionary d = new ResourceDictionary();
     d.Add("vm", new AdvancedEditVM(db, AnimeToChange));
     this.Resources.MergedDictionaries.Add(d);
     InitializeComponent();
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: misupov/Turbina
        public static void Main(string[] args)
        {
            var application = new Application();
            var resourceDictionary = new ResourceDictionary();
            resourceDictionary.Add("Dunno", new LinearGradientBrush());
            resourceDictionary.Add("Dunno1", new LinearGradientBrush(Color.FromRgb(0x35, 0x56, 0xc6), Color.FromRgb(0x20, 0x39, 0x77),
                    new Point(0, 0), new Point(0, 1)));
            resourceDictionary.Add("Dunno2", new LinearGradientBrush(Colors.Peru, Colors.Coral, new Point(0, 0), new Point(0, 1)));
            application.Resources = resourceDictionary;

            var cb = new ContainerBuilder();
            cb.RegisterModule<TurbinaModule>().RegisterModule<TurbinaNodesModule>();
            var container = cb.Build();

            application.Run(new MainWindow(container));
        }
コード例 #3
0
    public static void ExportViewToXaml( ViewBase view, string fileName )
    {
      if( view == null )
        throw new ArgumentNullException( "view" );

      object value;
      DependencyProperty dp;
      ResourceDictionary resourceDictionary = new ResourceDictionary();
      Type viewType = view.GetType();
      Style viewStyle = new Style( viewType );

      foreach( FieldInfo fieldInfo in viewType.GetFields( BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static ) )
      {
        dp = fieldInfo.GetValue( view ) as DependencyProperty;

        if( dp != null )
        {
          value = view.ReadLocalValue( dp );

          if( value != DependencyProperty.UnsetValue )
            viewStyle.Setters.Add( new Setter( dp, value ) );
        }
      }

      resourceDictionary.Add( viewType, viewStyle );

      XmlWriterSettings settings = new XmlWriterSettings();
      settings.Indent = true;
      settings.OmitXmlDeclaration = true;

      using( XmlWriter xmlWriter = XmlWriter.Create( fileName, settings ) )
      {
        XamlWriter.Save( resourceDictionary, xmlWriter );
      }
    }
コード例 #4
0
ファイル: ResourceDictionaries.cs プロジェクト: kib357/Ester2
        //private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
        public static ResourceDictionary GetDictionary(string relativePath = @"Resources\Dictionaries")
        {
            var mergedDictionary = new ResourceDictionary();
            string path = Path.Combine(HttpRuntime.AppDomainAppPath, relativePath);

            if (Directory.Exists(path))
                foreach (string fileName in Directory.GetFiles(path).Where(f => f.EndsWith(".xaml")))
                    using (var fs = new FileStream(fileName, FileMode.Open))
                    {
                        try
                        {
                            var xr = new XamlReader();

                            var tmp = (ResourceDictionary)XamlReader.Load(fs);
                            foreach (string key in tmp.Keys)
                                if (tmp[key] is Canvas)
                                {
                                    mergedDictionary.Add(key, tmp[key]);
                                }

                        }
                        catch (Exception)
                        {
                            //_logger.Error(ex.Message);
                        }
                    }
            else
                Directory.CreateDirectory(path);

            return mergedDictionary;
        }
コード例 #5
0
 public void FillupResource(ResourceDictionary res)
 {
     foreach (var fd in FrameDescriptions.Values)
     {
         res.Add(GetBrushResourceNameForDescriptor(fd.Descriptor),
             new SolidColorBrush(fd.HighlightColor));
     }
 }
コード例 #6
0
ファイル: MainWindow.cs プロジェクト: ClemensT/WPF-Samples
 private void ChangeRd(ResourceDictionary rd, string newKey, object newValue)
 {
     if (!rd.Contains(newKey))
     {
         rd.Add(newKey, newValue);
         SaveChange();
     }
 }
コード例 #7
0
        public static ResourceDictionary CreateAccentColorResourceDictionary(this Color color)
        {
            if (_accentColorResourceDictionary != null)
            {
                return _accentColorResourceDictionary;
            }
            var resourceDictionary = new ResourceDictionary();

            resourceDictionary.Add("NotificationAccentColor", color);

            resourceDictionary.Add("NotificationAccentColorBrush", new SolidColorBrush((Color) resourceDictionary["NotificationAccentColor"]));

            var application = Application.Current;
            var applicationResources = application.Resources;
            applicationResources.MergedDictionaries.Insert(0, resourceDictionary);

            _accentColorResourceDictionary = resourceDictionary;
            return applicationResources;
        }
コード例 #8
0
 public static ResourceDictionary WrapInResourceDictionary(object obj)
 {
     var rd = new ResourceDictionary();
     var list = obj as IEnumerable;
     if (list != null)
     {
         int i = 1;
         foreach (var o in list)
         {
             rd.Add("Model" + i, o);
             i++;
         }
     }
     else
     {
         rd.Add("Model", obj);
     }
     return rd;
 }
コード例 #9
0
ファイル: ThemeManager.cs プロジェクト: ritics/MahApps.Metro
        private static void ApplyResourceDictionary(ResourceDictionary newRd, ResourceDictionary oldRd)
        {
            foreach (DictionaryEntry r in newRd)
            {
                if (oldRd.Contains(r.Key))
                    oldRd.Remove(r.Key);

                oldRd.Add(r.Key, r.Value);
            }
        }
コード例 #10
0
ファイル: Tests.cs プロジェクト: JeanNguon/Projet
        public Tests()
        {
            if (applicationService == null)
            {
                Console.WriteLine("Initialisation des Tests");

                Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
                {
                    Source =
                        new Uri(
                        "/Proteca.SilverlightUnitTest;component/Assets/Styles.xaml",
                        UriKind.RelativeOrAbsolute)
                });
                Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
                {
                    Source =
                        new Uri(
                        "/Proteca.SilverlightUnitTest;component/Assets/GridView.xaml",
                        UriKind.RelativeOrAbsolute)
                });
                Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
                {
                    Source =
                        new Uri(
                        "/Proteca.SilverlightUnitTest;component/Assets/Boutons.xaml",
                        UriKind.RelativeOrAbsolute)
                });
                Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
                {
                    Source =
                        new Uri(
                        "/Proteca.SilverlightUnitTest;component/Assets/TileView.xaml",
                        UriKind.RelativeOrAbsolute)
                });
                ResourceDictionary dic = new ResourceDictionary();
                dic.Add("ApplicationResources", new Proteca.Silverlight.ApplicationResources());
                Application.Current.Resources.MergedDictionaries.Add(dic);

                if (Application.Current.Resources.Any(r => r.Key.ToString() == "ServiceHostAdress"))
                {
                    Application.Current.Resources.Remove("ServiceHostAdress");
                }
                Application.Current.Resources.Add("ServiceHostAdress", "http://verd174:90/");
                if (!Application.Current.Resources.Any(r => r.Key.ToString() == "DebugLogin"))
                {
                    Application.Current.Resources.Add("DebugLogin", "n.cossard");
                }

                if (applicationService == null)
                {
                    applicationService = new ApplicationService();
                    applicationService.StartService(null);
                }
            }
        }
コード例 #11
0
 private static Style GetItemContainerStyle()
 {
     Style listBoxItemStyle = new Style(typeof(ListBoxItem));
     listBoxItemStyle.Setters.Add(new Setter(ListBox.FocusVisualStyleProperty, null));   // убираем рамку из точек вокруг выделенного элемента
     listBoxItemStyle.Setters.Add(new Setter(ListBox.PaddingProperty, new Thickness(0)));    // убираем отступы от края родительского элемента
     listBoxItemStyle.Setters.Add(new Setter(ListBoxItem.MarginProperty, new Thickness(0, 0, 0, 1)));    // добавляем отступ снизу каждого элемента
     ResourceDictionary resources = new ResourceDictionary();
     resources.Add(SystemColors.HighlightBrushKey, new SolidColorBrush(Colors.Transparent));
     listBoxItemStyle.Resources = resources;
     return listBoxItemStyle;
 }
コード例 #12
0
ファイル: ToggleButtonStyle.cs プロジェクト: kswoll/restless
        public static void Register(ResourceDictionary resources)
        {
            var buttonTemplate = new FrameworkElementFactory(typeof(ButtonTemplate));

            var controlTemplate = new ControlTemplate(typeof(ToggleButton));
            controlTemplate.VisualTree = buttonTemplate;

            var style = new Style(typeof(ToggleButton));
            style.Setters.Add(new Setter(Control.TemplateProperty, controlTemplate));

            resources.Add(typeof(ToggleButton), style);
        }
コード例 #13
0
ファイル: RemoteAgentTag.cs プロジェクト: NoahRic/TypingAgent
        /// <summary>
        /// Create a remote agent with the given name
        /// </summary>
        public static RemoteAgentTag CreateRemoteAgent(string agentName, ITextView view, IEditorFormatMap formatMap)
        {
            Dictionary<string, RemoteAgentTag> existingAgents = GetExistingAgents(view);

            RemoteAgentTag agent;
            if (existingAgents.TryGetValue(agentName, out agent))
                return agent;

            var brushes = _brushes[existingAgents.Count % _brushes.Count];

            ResourceDictionary agentDictionary = new ResourceDictionary();
            agentDictionary.Add(MarkerFormatDefinition.BorderId, brushes.Item1);
            agentDictionary.Add(MarkerFormatDefinition.FillId, brushes.Item2);

            formatMap.AddProperties(agentName, agentDictionary);

            agent = new RemoteAgentTag(agentName);
            existingAgents[agentName] = agent;

            return agent;
        }
コード例 #14
0
ファイル: TextBoxStyle.cs プロジェクト: kswoll/restless
        public static void Register(ResourceDictionary resources)
        {
            var textBoxTemplate = new FrameworkElementFactory(typeof(TextBoxTemplate));
            textBoxTemplate.AppendChild(new FrameworkElementFactory(typeof(ScrollViewer), "PART_ContentHost"));

            var controlTemplate = new ControlTemplate(typeof(TextBox));
            controlTemplate.VisualTree = textBoxTemplate;

            var style = new Style(typeof(TextBox));
            style.Setters.Add(new Setter(Control.TemplateProperty, controlTemplate));

            resources.Add(typeof(TextBox), style);
        }
コード例 #15
0
        public void TemplateAndStyleFindDefaultTest()
        {
            Style style = new Style { TargetType = typeof(Control) };
            style.Setters.Add(new Setter { Property = new DependencyPropertyPathElement(FrameworkElement.WidthProperty), Value = 100 });

            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 StyleKey(typeof(Control)), style);
            resources.Add(new TemplateKey(typeof(Control)), controlTemplate);

            Control control = new Control();
            control.Resources = resources;

            Assert.AreEqual(style, control.Style);
            Assert.AreEqual(controlTemplate, control.Template);
        }
コード例 #16
0
ファイル: ChartHelper.cs プロジェクト: WhiteIsland/epiworx
        public static void AddColor(ResourceDictionaryCollection palette,
            Color color)
        {
            var style = new Style(typeof(Control));

            style.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(color)));
            style.Setters.Add(new Setter(Control.BorderThicknessProperty, "0"));
            style.Setters.Add(new Setter(Control.BorderBrushProperty, new SolidColorBrush(Color.FromArgb(255, 255, 255, 255))));

            var dictionary = new ResourceDictionary();
            dictionary.Add("DataPointStyle", style);

            palette.Add(dictionary);
        }
コード例 #17
0
 public AnimeEditWindow(a_animes animeToChange, AniMoDBEntities db, bool newAnime = false)
 {
     ResourceDictionary m = new ResourceDictionary();
     m.Add("vm", new AnimeEditVM(animeToChange, db, this));
     this.Resources.MergedDictionaries.Add(m);
     InitializeComponent();
     if (newAnime)
     {
         AdvancedView.IsEnabled = false;
     } else
     {
         AdvancedView.IsEnabled = true;
     }
 }
コード例 #18
0
ファイル: Theme.cs プロジェクト: nikhilk/silverlightfx
        internal static void LoadTheme(ResourceDictionary targetResources, string name)
        {
            ThemeInfo theme = new ThemeInfo();

            string themeXaml = GetThemeXaml(name, "Theme", /* lookupShared */ false);
            try {
                ExtractThemeContent(themeXaml, theme, /* extractIncludes */ true);
                if ((theme.Includes.Length == 0) && (theme.Keys.Count != 0)) {
                    UserControl userControl = (UserControl)XamlReader.Load(themeXaml);
                    ResourceDictionary themeResources = userControl.Resources;

                    foreach (string key in theme.Keys) {
                        targetResources.Add(key, themeResources[key]);
                    }

                    return;
                }
            }
            catch (Exception e) {
                throw new InvalidOperationException("The theme named '" + name + "' contained invalid XAML.", e);
            }

            if (theme.Includes.Length != 0) {
                string[] includes = theme.Includes.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < includes.Length; i++) {
                    string includeXaml = GetThemeXaml(name, includes[i], /* lookupShared */ true);
                    try {
                        ExtractThemeContent(includeXaml, theme, /* extractIncludes */ false);
                    }
                    catch (Exception e) {
                        throw new InvalidOperationException("The include named '" + includes[i] + "' in the theme named '" + name + "' contained invalid XAML.", e);
                    }
                }
            }

            try {
                string mergedXaml = theme.GetXml();
                UserControl userControl = (UserControl)XamlReader.Load(mergedXaml);
                ResourceDictionary themeResources = userControl.Resources;

                foreach (string key in theme.Keys) {
                    targetResources.Add(key, themeResources[key]);
                }
            }
            catch (Exception e) {
                throw new InvalidOperationException("The theme named '" + name + "' contained invalid XAML.", e);
            }
        }
コード例 #19
0
        public void ResourceReferenceExpressionBaseTest()
        {
            FrameworkElement root = new FrameworkElement();
            FrameworkElement child1 = new FrameworkElement();
            FrameworkElement child2 = new FrameworkElement();

            child1.AddVisualChild(child2);

            int testValueChanged = 0;
            child2.PropertyChanged += (sender, e) => testValueChanged += e.Property == TestValueProperty ? 1 : 0;

            child2.SetValue(TestValueProperty, new ResourceReferenceExpressionProvider("key1"));

            Assert.AreEqual("default", child2.GetValue(TestValueProperty));
            Assert.AreEqual(0, testValueChanged);

            root.Resources = new ResourceDictionary();
            root.Resources.Add("key1", "value1");
            root.AddVisualChild(child1);

            Assert.AreEqual("value1", child2.GetValue(TestValueProperty));
            Assert.AreEqual(1, testValueChanged);

            root.Resources.Remove("key1");

            Assert.AreEqual("default", child2.GetValue(TestValueProperty));
            Assert.AreEqual(2, testValueChanged);

            ResourceDictionary dictionary = new ResourceDictionary();
            dictionary.Add("key1", "value2");

            root.Resources.MergedDictionaries.Add(dictionary);

            Assert.AreEqual("value2", child2.GetValue(TestValueProperty));
            Assert.AreEqual(3, testValueChanged);

            child1.Resources = new ResourceDictionary();
            child1.Resources.Add("key1", "value3");

            Assert.AreEqual("value3", child2.GetValue(TestValueProperty));
            Assert.AreEqual(4, testValueChanged);

            child1.Resources.Remove("key1");

            Assert.AreEqual("value2", child2.GetValue(TestValueProperty));
            Assert.AreEqual(5, testValueChanged);
        }
コード例 #20
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);
            }
        }
コード例 #21
0
        internal static void ApplyCore(System.Windows.ResourceDictionary resources, ThemeDictionaryBase themeResources)
        {
            ValidationHelper.NotNull(resources, "resources");
            ValidationHelper.NotNull(themeResources, "themeResources");

            // Bug in WPF 4: http://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references
            if (resources.Keys.Count == 0)
            {
                resources.Add(typeof(Window), new Style(typeof(Window)));
            }

            var genericDictionary = new System.Windows.ResourceDictionary {
                Source = GenericDictionaryUri
            };

            genericDictionary.MergedDictionaries.Clear();
            genericDictionary.MergedDictionaries.Add(ThemeDictionaryConverter.Convert(themeResources));
            resources.SafeInject(genericDictionary);
        }
コード例 #22
0
        /// <summary>
        /// Used to create and initialise the template selector and the
        /// resources that it references.
        /// </summary>
        /// <param name="dictionary"></param>
        public static void Prepare(ResourceDictionary dictionary)
        {
            // TODO: Need to find path to load Visualizer plugins
            // Fsi "shadow copy" visualizer hack: it sets this env var for us to use
            var basePath = Environment.GetEnvironmentVariable("FSI_SHADOW_PATH");
            if (String.IsNullOrEmpty(basePath))
                basePath = AppDomain.CurrentDomain.BaseDirectory;

            // Different path for this?
            var catalog = new DirectoryCatalog(basePath, @"*Visualizer*.dll");
            var container = new CompositionContainer(catalog);

            // Resources are merged into the passed dictionary, and which point
            // we no longer require a reference to the loader.
            var loader = new ComponentResourceLoader();
            container.ComposeParts(loader);
            loader.Load(dictionary);

            // Template selector is initialised and added to resources.
            var selector = new ComponentTemplateSelector();
            container.ComposeParts(selector);
            dictionary.Add("componentSelector", selector);
        }
コード例 #23
0
ファイル: ResourceDictionaryTest.cs プロジェクト: dfr0/moon
		public void InterfaceTest ()
		{
			IDictionary<object, object> d = new ResourceDictionary ();
			Assert.Throws<ArgumentException> (delegate {
				d.Add (new KeyValuePair<object, object> (new object (), new object ()));
			}, "#1");
			d.Add (new KeyValuePair<object, object> ("bob", new object ()));
			Assert.Throws<NotImplementedException> (delegate {
				int a = d.Count;
				GC.KeepAlive (a);
			}, "#2");
			Assert.AreEqual (1, ((ResourceDictionary) d).Count, "#3");
			Assert.Throws<ArgumentException> (delegate {
				d.Add (new object (), new object ());
			}, "#4");
			d.Add ("str", new object ());
			Assert.AreEqual (2, ((ResourceDictionary) d).Count, "#5");
			Assert.Throws<ArgumentException> (delegate {
				d.ContainsKey (new object ());
			}, "#6");
			Assert.IsTrue (d.Contains (new KeyValuePair<object, object> ("str", new object ())), "#7");
			d.Clear ();
			Assert.AreEqual (0, ((ResourceDictionary) d).Count, "#8");

			// this doesn't throw in SL4 for any runtime version
			d.GetEnumerator ();

			Assert.Throws<NotImplementedException> (delegate {
				var v = d.Keys;
				GC.KeepAlive (v);
			}, "#10");
			Assert.Throws<NotImplementedException> (delegate {
				var v = d.Values;
				GC.KeepAlive (v);
			}, "#11");
			Assert.IsFalse (d.IsReadOnly, "#12");
			Assert.Throws<NotImplementedException> (delegate {
				d.CopyTo (new KeyValuePair<object, object> [10], 0);
			}, "#13");
		}
コード例 #24
0
ファイル: Page.xaml.cs プロジェクト: NALSS/epiinfo-82474
        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            RotateTransform rotateTransform = new RotateTransform();
            rotateTransform.Angle = 0.90;

            _rotateStyle.Setters.Add(new Setter(CategoryAxis.RenderTransformProperty, rotateTransform));

            if (App.Current.Resources.Contains("chartTitle"))
            {
                _chartTitle = App.Current.Resources["chartTitle"].ToString();
                Chart.Title = _chartTitle;
            }
            if (App.Current.Resources.Contains("independentLabel"))
            {
                _independentLabel = App.Current.Resources["independentLabel"].ToString();
            }

            if (App.Current.Resources.Contains("dependentLabel"))
            {
                _dependentLabel = App.Current.Resources["dependentLabel"].ToString();
            }

            if (App.Current.Resources.Contains("chartLineSeries"))
            {
                _chartLineSeries = App.Current.Resources["chartLineSeries"].ToString();
                _chartLineSeries = _chartLineSeries.Replace(Statics.Comma, ",");
            }

            if (App.Current.Resources.Contains("chartType"))
            {
                _chartType = App.Current.Resources["chartType"].ToString();
                List<object> objectList = new List<object>();

                if (ProcessSeriesData(ref objectList, _chartType, _chartLineSeries, ref _failOverMessage))
                {
                    try
                    {
                        switch (_chartType.ToUpper().Replace(" ", ""))
                        {
                            case Statics.Area:
                                foreach (object line in objectList)
                                {
                                    Chart.Series.Add(line as AreaSeries);
                                }
                                break;

                            case Statics.Bar:

                                foreach (object columnSeries in objectList)
                                {
                                    #region REM rotate label candidate
                                    //if (independentValue.GetType() == Type.GetType("System.String"))
                                    //{
                                    //    //Style style = new Style(typeof(CategoryAxis));
                                    //    //RotateTransform rotateTransform = new RotateTransform();
                                    //    //rotateTransform.Angle = 0.90;

                                    //    //style.Setters.Add(new Setter(CategoryAxis.RenderTransformProperty, rotateTransform));

                                    //    //((ColumnSeries)series).IndependentAxis = new CategoryAxis
                                    //    //{
                                    //    //    Title = _independentLabel,
                                    //    //    Orientation = AxisOrientation.X,
                                    //    //    AxisLabelStyle = _rotateStyle
                                    //    //};

                                    //    ((ColumnSeries)series).IndependentAxis = new CategoryAxis
                                    //    {
                                    //        Title = _independentLabel,
                                    //        Orientation = AxisOrientation.X
                                    //    };
                                    //}
                                    //else if (independentValue.GetType() == Type.GetType("System.DateTime"))
                                    //{
                                    //    ((ColumnSeries)series).IndependentAxis = new DateTimeAxis
                                    //    {
                                    //        Title = _independentLabel,
                                    //        Orientation = AxisOrientation.X
                                    //    };
                                    //}
                                    //else
                                    //{
                                    //    ((ColumnSeries)series).IndependentAxis = new LinearAxis
                                    //    {
                                    //        Title = _independentLabel,
                                    //        Orientation = AxisOrientation.X
                                    //    };
                                    //}
                                    #endregion
                                    Chart.Series.Add(columnSeries as ColumnSeries);
                                }
                                #region REM rotate label candidate
                                //((ColumnSeries)objectList[0] as ColumnSeries).DependentRangeAxis = new LinearAxis
                                //{
                                //    Title = _dependentLabel,
                                //    ShowGridLines = true,
                                //    Orientation = AxisOrientation.Y
                                //};
                                #endregion
                                break;

                            case Statics.Bubble:
                                foreach (object line in objectList)
                                {
                                    Chart.Series.Add(line as BubbleSeries);
                                }
                                break;

                            case Statics.RotatedBar:
                                foreach (object line in objectList)
                                {
                                    Chart.Series.Add(line as BarSeries);
                                }
                                break;

                            case Statics.Histogram:
                                foreach (object line in objectList)
                                {
                                    System.Windows.Controls.DataVisualization.ResourceDictionaryCollection pallete = new ResourceDictionaryCollection();
                                    ResourceDictionary rd = new ResourceDictionary();
                                    Style style = new Style();
                                    style.TargetType = typeof(ColumnDataPoint);

                                    style.Setters.Clear();
                                    //style.Setters.Add(new Setter() { Property = ColumnDataPoint.BackgroundProperty, Value = new SolidColorBrush(Colors.Orange) });
                                    style.Setters.Add(new Setter() { Property = ColumnDataPoint.MarginProperty, Value = new Thickness(0) });
                                    style.Setters.Add(new Setter() { Property = ColumnDataPoint.PaddingProperty, Value = new Thickness(0, 0, 0, 0) });
                                    style.Setters.Add(new Setter() { Property = ColumnDataPoint.MinWidthProperty, Value = 256 });

                                    rd.Clear();
                                    rd.Add("DataPointStyle", style);
                                    pallete.Clear();
                                    pallete.Add(rd);
                                    Chart.Palette = pallete;

                                    Chart.Series.Add(line as ColumnSeries);
                                }
                                break;

                            case Statics.Line:
                                foreach (object line in objectList)
                                {
                                    Chart.Series.Add(line as LineSeries);
                                }
                                break;

                            case Statics.Pie:
                                foreach (object column in objectList)
                                {
                                    Chart.Series.Add(column as PieSeries);
                                }
                                break;

                            case Statics.Scatter:
                                foreach (object line in objectList)
                                {
                                    Chart.Series.Add(line as ScatterSeries);
                                }
                                break;

                            case Statics.Stacked:
                                foreach (object line in objectList)
                                {
                                    Chart.Series.Add(line as StackedBarSeries);
                                }
                                break;

                            default:
                                _failOverMessage = "The specified graph type supplied in the input parameters (initParams) could not be parsed or is not supported.";
                                break;
                        }
                    }
                    catch (Exception exception)
                    {
                        _failOverMessage = exception.Message;
                    }
                }
                else
                {
                    if (_failOverMessage == string.Empty)
                    {
                        _failOverMessage = "The input parameters (initParams) could not be parsed.";
                    }
                }

                if (_failOverMessage.Length > 0)
                {
                    Chart.Visibility = Visibility.Collapsed;
                    FailOverMessage.Text = _failOverMessage;
                }
            }
        }
コード例 #25
0
        private PackagesProviderBase CreatePackagesProviderBase()
        {
            ResourceDictionary resources = new ResourceDictionary();
            resources.Add("PackageItemTemplate", new DataTemplate());
            resources.Add("PackageDetailTemplate", new DataTemplate());

            return new ConcretePackagesProvider(resources);
        }
コード例 #26
0
        public void ReplacePrimaryColor(Swatch swatch)
        {
            if (swatch == null) throw new ArgumentNullException(nameof(swatch));

            ResourceDictionary oldColorResourceDictionary;
            if (!TryFindSwatchDictionary(Application.Current.Resources, "PrimaryHueMidBrush", out oldColorResourceDictionary))
                throw new ApplicationException("Unable to find primary color definition in Application resources.");

            var list = swatch.PrimaryHues.ToList();
            var light = list[2];
            var mid = swatch.ExemplarHue;
            var dark = list[7];

            //TODO reuse some of the dupes, freeze.

            var newColorResourceDictionary = new ResourceDictionary
            {
                {"PrimaryHueLightBrush", new SolidColorBrush(light.Color)},
                {"PrimaryHueLightForegroundBrush", new SolidColorBrush(light.Foreground)},
                {"PrimaryHueMidBrush", new SolidColorBrush(mid.Color)},
                {"PrimaryHueMidForegroundBrush", new SolidColorBrush(mid.Foreground)},
                {"PrimaryHueDarkBrush", new SolidColorBrush(dark.Color)},
                {"PrimaryHueDarkForegroundBrush", new SolidColorBrush(dark.Foreground)}
            };

            if (oldColorResourceDictionary.Keys.OfType<string>().Contains("HighlightBrush"))
            {
                newColorResourceDictionary.Add("HighlightBrush", new SolidColorBrush(dark.Color));
                newColorResourceDictionary.Add("AccentColorBrush", new SolidColorBrush(list[5].Color));
                newColorResourceDictionary.Add("AccentColorBrush2", new SolidColorBrush(list[4].Color));
                newColorResourceDictionary.Add("AccentColorBrush3", new SolidColorBrush(list[3].Color));
                newColorResourceDictionary.Add("AccentColorBrush4", new SolidColorBrush(list[2].Color));
                newColorResourceDictionary.Add("WindowTitleColorBrush", new SolidColorBrush(dark.Color));
                newColorResourceDictionary.Add("AccentSelectedColorBrush", new SolidColorBrush(list[5].Foreground));
                newColorResourceDictionary.Add("ProgressBrush", new LinearGradientBrush(dark.Color, list[3].Color, 90.0));
                newColorResourceDictionary.Add("CheckmarkFill", new SolidColorBrush(list[5].Color));
                newColorResourceDictionary.Add("RightArrowFill", new SolidColorBrush(list[5].Color));
                newColorResourceDictionary.Add("IdealForegroundColorBrush", new SolidColorBrush(list[5].Foreground));
                newColorResourceDictionary.Add("IdealForegroundDisabledBrush", new SolidColorBrush(dark.Color) { Opacity = .4 });
            }

            Application.Current.Resources.MergedDictionaries.Remove(oldColorResourceDictionary);
            Application.Current.Resources.MergedDictionaries.Add(newColorResourceDictionary);
        }
コード例 #27
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);
        }
コード例 #28
0
        public static ResourceDictionary GetResourceDictionary(string _dictionaryName)
        {
            var resDict = new ResourceDictionary();

            WeakReference reference;
            if (m_sharedDictionaries.TryGetValue(_dictionaryName, out reference))
            {
                return (ResourceDictionary)reference.Target;
            }
            // if (result == null)

            var assemblyName = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().ManifestModule.Name);
            var result = Application.LoadComponent(new Uri(assemblyName + ";component/Resources/" + _dictionaryName + ".xaml", UriKind.Relative)) as ResourceDictionary;

            for (int index = 0; index < result.MergedDictionaries.Count; index++)
            {
                var resourceDictionary = GetResourceDictionary(Path.GetFileNameWithoutExtension(result.MergedDictionaries[index].Source.OriginalString));
                resDict.MergedDictionaries.Add(resourceDictionary);
            }

            foreach (var key in result.Keys)
            {
                if (result[key] is SolidColorBrush)
                {
                    var br = (SolidColorBrush)result[key];
                    var add = new SolidColorBrush { Opacity = br.Opacity, Color = (m_colors.ContainsKey(br.Color) ? m_colors[br.Color] : br.Color) };
                    resDict.Add(key, add);
                }
                else if (result[key] is LinearGradientBrush)
                {
                    var br = (LinearGradientBrush)result[key];
                    var add = new LinearGradientBrush { StartPoint = br.StartPoint, EndPoint = br.EndPoint, ColorInterpolationMode = br.ColorInterpolationMode, Opacity = br.Opacity, };
                    foreach (var gradientStop in br.GradientStops)
                    {
                        if (m_colors.ContainsKey(gradientStop.Color))
                        {
                            add.GradientStops.Add(new GradientStop(m_colors[gradientStop.Color], gradientStop.Offset));
                        }
                        else
                        {
                            add.GradientStops.Add(gradientStop);
                        }
                    }
                    resDict.Add(key, add);
                }
                else if (result[key] is RadialGradientBrush)
                {
                    var br = (RadialGradientBrush)result[key];
                    var add = new RadialGradientBrush { Center = br.Center, ColorInterpolationMode = br.ColorInterpolationMode, GradientOrigin = br.GradientOrigin, RadiusX = br.RadiusX, RadiusY = br.RadiusY };
                    foreach (var gradientStop in br.GradientStops)
                    {
                        if (m_colors.ContainsKey(gradientStop.Color))
                        {
                            add.GradientStops.Add(new GradientStop(m_colors[gradientStop.Color], gradientStop.Offset));
                        }
                        else
                        {
                            add.GradientStops.Add(gradientStop);
                        }
                    }
                    resDict.Add(key, add);
                }
                else if (result[key] is Color)
                {
                    foreach (var pair in ChangeColors)
                    {
                        if ((key as string) == "BCKH" + pair.Key)
                        {
                            var color = Color.FromArgb(0x80, pair.Value.R, pair.Value.G, pair.Value.B);
                            m_colors.Add((Color)result[key], color);
                            resDict.Add(key, color);
                        }
                        else if ((key as string) == "BCKQ" + pair.Key)
                        {
                            var color = Color.FromArgb(0x40, pair.Value.R, pair.Value.G, pair.Value.B);
                            m_colors.Add((Color)result[key], color);
                            resDict.Add(key, color);
                        }
                        else if ((key as string) == "BCKO" + pair.Key)
                        {
                            var color = Color.FromArgb(0x20, pair.Value.R, pair.Value.G, pair.Value.B);
                            m_colors.Add((Color)result[key], color);
                            resDict.Add(key, color);
                        }
                        else if ((key as string) == "BCK" + pair.Key)
                        {
                            m_colors.Add((Color)result[key], pair.Value);
                            //m_colors.Add((Color)result[key], (Color)result[key]);

                            resDict.Add(key, pair.Value);
                        }
                    }
                }
                else
                {
                    resDict.Add(key, result[key]);
                }

            }
            m_sharedDictionaries[_dictionaryName] = new WeakReference(resDict);
            return resDict;
        }
コード例 #29
0
ファイル: ResourceDictionaryTest.cs プロジェクト: dfr0/moon
		public void MergedDictionaries_KeyClashes ()
		{
			var key = "Key";
			var value = new object ();
			var value1 = new object ();
			var value2 = new object ();

			var merge1 = new ResourceDictionary ();
			var merge2 = new ResourceDictionary ();
			ResourceDictionary main = new ResourceDictionary ();
			main.MergedDictionaries.Add (merge1);
			main.MergedDictionaries.Add (merge2);

			main.Add (key, value);
			merge1.Add (key, value1);
			merge2.Add (key, value2);
			
			// We ignore the values in the merged dictionaries if the main dictionary
			// has the key
			Assert.AreEqual (value, main [key], "#1");

			main.Remove (key);

			// We should look up the merged dictionaries in reverse order
			Assert.AreEqual (value2,main [key],  "#2");

			merge2.Remove (key);

			// Now we should find it in the first merged dictionary
			Assert.AreEqual (value1, main [key], "#3");
		}
コード例 #30
0
ファイル: ResourceDictionaryTest.cs プロジェクト: dfr0/moon
		public void Clear ()
		{
			ResourceDictionary rd = new ResourceDictionary ();
			rd.Add ("key", new object ());
			Assert.AreEqual (1, rd.Count, "Count-1");
			rd.Clear ();
			Assert.AreEqual (0, rd.Count, "Count-2");
		}
コード例 #31
0
ファイル: ResourceDictionaryTest.cs プロジェクト: dfr0/moon
		public void Contains_TypeAndStringInResourceDictionary_TypeSecond()
		{
			var rd = new ResourceDictionary();
			rd.Add("System.Windows.Controls.Button", "System.Windows.Controls.Button");
			Assert.IsTrue(rd.Contains("System.Windows.Controls.Button"), "#1");
			Assert.IsFalse (rd.Contains(typeof (Button)), "#2");

			Assert.Throws<ArgumentException>(() => {
				rd.Add(typeof(Button), new Style { TargetType = typeof(Button) });
			}, "#3");
		}