本文整理汇总了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;
}
示例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;
}
示例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
});
//.........这里部分代码省略.........
示例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;
}