当前位置: 首页>>代码示例>>C#>>正文


C# Grid.SetResourceReference方法代码示例

本文整理汇总了C#中System.Windows.Controls.Grid.SetResourceReference方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.SetResourceReference方法的具体用法?C# Grid.SetResourceReference怎么用?C# Grid.SetResourceReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Grid的用法示例。


在下文中一共展示了Grid.SetResourceReference方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SwatchesWindowControl

        /// <summary>
        /// Initializes a new instance of the <see cref="SwatchesWindowControl"/> class.
        /// </summary>
        public SwatchesWindowControl()
        {
            InitializeComponent();
            Type environmentColors = typeof(EnvironmentColors);
            double tileSize = CalculateTileSize();

            foreach (PropertyInfo property in environmentColors.GetProperties(BindingFlags.Public | BindingFlags.Static))
            {
                if (property.Name.EndsWith("BrushKey"))
                {
                    Grid tile = new Grid
                    {
                        Width = tileSize,
                        Height = tileSize,
                        Tag = property.Name,
                        ToolTip = property.Name
                    };

                    tile.SetResourceReference(BackgroundProperty, property.GetValue(null));
                    tile.MouseDown += TileOnMouseDown;
                    Root.Children.Add(tile);
                }
            }

            SizeChanged += OnSizeChanged;
        }
开发者ID:NotYours180,项目名称:ExtensibilityTools,代码行数:29,代码来源:SwatchesWindowControl.xaml.cs

示例2: ThemedWindow

        public ThemedWindow()
        {
            this.ShouldBeThemed();

            WindowStyle = WindowStyle.None;
            ResizeMode = ResizeMode.CanResizeWithGrip;
            Background = Brushes.Transparent;
            AllowsTransparency = true;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            ShowInTaskbar = false;

            Grid host = new Grid();
            //Header
            host.RowDefinitions.Add(new RowDefinition
            {
                Height = GridLength.Auto
            });
            //Body
            host.RowDefinitions.Add(new RowDefinition());

            FrameworkElement header = BuildHeaderArea();
            header.SetValue(Grid.RowProperty, 0);
            host.Children.Add(header);

            ContentPresenter contentPresenter = new ContentPresenter();
            contentPresenter.SetValue(Grid.RowProperty, 1);
            contentPresenter.SetBinding(ContentPresenter.ContentProperty, new Binding
            {
                Mode = BindingMode.OneWay,
                RelativeSource = new RelativeSource
                {
                    Mode = RelativeSourceMode.FindAncestor,
                    AncestorType = typeof(ThemedWindow)
                },
                Path = new PropertyPath("Content")
            });
            contentPresenter.Resources = Resources;
            host.Children.Add(contentPresenter);

            host.SetResourceReference(BackgroundProperty, EnvironmentColors.ToolWindowBackgroundBrushKey);

            Border hostContainer = new Border
            {
                Child = host,
                //Margin = new Thickness(1, 1, 5, 5),
                BorderThickness = new Thickness(1)
            };
            hostContainer.SetResourceReference(BorderBrushProperty, EnvironmentColors.MainWindowActiveDefaultBorderBrushKey);
            //hostContainer.Effect = new DropShadowEffect
            //{
            //    Direction = -75,
            //    ShadowDepth = 2,
            //    BlurRadius = 2,
            //    Color = Colors.Azure
            //};

            base.Content = hostContainer;
        }
开发者ID:madskristensen,项目名称:Packman,代码行数:58,代码来源:ThemedWindow.cs

示例3: BuildHeaderArea

        private FrameworkElement BuildHeaderArea()
        {
            Grid header = new Grid();
            header.ColumnDefinitions.Add(new ColumnDefinition());
            header.ColumnDefinitions.Add(new ColumnDefinition {Width = GridLength.Auto});
            header.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });

            //Move grip containing the icon and title
            Grid moveGrip = new Grid();
            moveGrip.ColumnDefinitions.Add(new ColumnDefinition
            {
                Width = GridLength.Auto
            });
            moveGrip.ColumnDefinitions.Add(new ColumnDefinition());
            moveGrip.SetResourceReference(Border.BackgroundProperty, EnvironmentColors.ToolWindowBackgroundBrushKey);
            moveGrip.SetValue(Grid.ColumnProperty, 0);
            moveGrip.MouseLeftButtonDown += TitleBarLeftMouseButtonDown;

            Image icon = new Image
            {
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(10, 5, 4, 0)
            };
            icon.SetBinding(Image.SourceProperty, new Binding
            {
                Source = this,
                Path = new PropertyPath("Icon"),
                Mode = BindingMode.OneWay
            });
            moveGrip.Children.Add(icon);

            Label label = new Label
            {
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(0, 2, 0, 0)
            };
            label.SetValue(Grid.ColumnProperty, 1);
            label.SetBinding(ContentControl.ContentProperty, new Binding
            {
                Source = this,
                Path = new PropertyPath("Title"),
                Mode = BindingMode.OneWay
            });
            label.SetResourceReference(ForegroundProperty, EnvironmentColors.MainWindowActiveCaptionTextBrushKey);
            moveGrip.Children.Add(label);
            header.Children.Add(moveGrip);

            //Close button
            FrameworkElement closeGlyph;
            Path buttonPath;
            GenerateCloseGlyph(out closeGlyph, out buttonPath);

            Style closeButtonStyle = new Style(typeof(Button));
            closeButtonStyle.Setters.Add(new Setter(HeightProperty, (double)25));
            closeButtonStyle.Setters.Add(new Setter(WidthProperty, (double)25));
            closeButtonStyle.Setters.Add(new Setter(FocusVisualStyleProperty, null));
            closeButtonStyle.Setters.Add(new Setter(ForegroundProperty, new DynamicResourceExtension(EnvironmentColors.MainWindowButtonActiveGlyphBrushKey)));
            closeButtonStyle.Setters.Add(new Setter(BackgroundProperty, null));
            closeButtonStyle.Setters.Add(new Setter(BorderBrushProperty, new DynamicResourceExtension(EnvironmentColors.MainWindowButtonActiveBorderBrushKey)));
            closeButtonStyle.Setters.Add(new Setter(TemplateProperty, FindResource("FlatButton")));

            Trigger closeButtonHoverTrigger = new Trigger
            {
                Property = IsMouseOverProperty,
                Value = true
            };

            closeButtonHoverTrigger.Setters.Add(new Setter(ForegroundProperty, new DynamicResourceExtension(EnvironmentColors.MainWindowButtonHoverActiveGlyphBrushKey)));
            closeButtonHoverTrigger.Setters.Add(new Setter(BackgroundProperty, new DynamicResourceExtension(EnvironmentColors.MainWindowButtonHoverActiveBrushKey)));
            closeButtonHoverTrigger.Setters.Add(new Setter(BorderBrushProperty, new DynamicResourceExtension(EnvironmentColors.MainWindowButtonHoverActiveBorderBrushKey)));
            closeButtonStyle.Triggers.Add(closeButtonHoverTrigger);

            Trigger closeButtonPressTrigger = new Trigger
            {
                Property = ButtonBase.IsPressedProperty,
                Value = true
            };

            closeButtonPressTrigger.Setters.Add(new Setter(ForegroundProperty, new DynamicResourceExtension(EnvironmentColors.MainWindowButtonDownGlyphBrushKey)));
            closeButtonPressTrigger.Setters.Add(new Setter(BackgroundProperty, new DynamicResourceExtension(EnvironmentColors.MainWindowButtonDownBrushKey)));
            closeButtonPressTrigger.Setters.Add(new Setter(BorderBrushProperty, new DynamicResourceExtension(EnvironmentColors.MainWindowButtonDownBorderBrushKey)));
            closeButtonStyle.Triggers.Add(closeButtonPressTrigger);

            Button closeButton = new Button
            {
                Style = closeButtonStyle,
                Name = "closeButton",
                Content = closeGlyph,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment = VerticalAlignment.Center
            };

            closeButton.SetValue(Grid.ColumnProperty, 2);
            header.Children.Add(closeButton);
            buttonPath.SetBinding(Shape.FillProperty, new Binding
            {
                Path = new PropertyPath("Foreground"),
                Source = closeButton,
                Mode = BindingMode.OneWay
            });
//.........这里部分代码省略.........
开发者ID:madskristensen,项目名称:Packman,代码行数:101,代码来源:ThemedWindow.cs

示例4: SetTabStyle

 //sets the style of the grid
 private bool SetTabStyle(Grid tab, Boolean toDefault)
 {
     if (toDefault)
         tab.SetResourceReference(Control.StyleProperty, "GridStyle_hover");
     else
         tab.SetResourceReference(Control.StyleProperty, "GridStyle_Selected");
     return true;
 }
开发者ID:rhlrjv,项目名称:CardioLeaf,代码行数:9,代码来源:MainWindow.xaml.cs


注:本文中的System.Windows.Controls.Grid.SetResourceReference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。