在我的Resource_Color ResourceDictionary中,我定义了这一行:
<Color x:Key="MainColor">Black</Color>现在,我想在另一个资源文件(例如Resource_DataGrid. )中使用这个MainColor
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="{StaticResource MainColor}" />。。。在这种模式下不起作用。我怎么写这份声明?
发布于 2015-10-21 15:54:04
使用ResourceDictionary.MergedDictionaries
Window1.xaml 1.
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="Auto" Width="Auto">
<Window.Resources>
<ResourceDictionary Source="Dictionary2.xaml" />
</Window.Resources>
<Grid>
<TextBox Text="TESTING" FontWeight="Bold" Margin="30" />
</Grid>
</Window>Dictionary1.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="MainColor">Blue</Color>
<SolidColorBrush x:Key="MainBrush" Color="{StaticResource MainColor}" />
</ResourceDictionary>Dictionary2.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TextBox">
<Setter Property="Foreground" Value="{StaticResource MainBrush}" />
</Style>
</ResourceDictionary>另外,前台属性通常是笔刷,而不是颜色。我的例子说明了这一点。
https://stackoverflow.com/questions/33262297
复制相似问题