.net 使我的样式特定于单个实例
我的wpf应用程序具有以下样式: Xaml: 它修改Xceed数据网格中的行的外观 这一切都很好 但我去给我的应用程序添加了另一个Xceed Datagrid,它也在使用这种风格.net 使我的样式特定于单个实例,.net,wpf,xaml,.net,Wpf,Xaml,我的wpf应用程序具有以下样式: Xaml: 它修改Xceed数据网格中的行的外观 这一切都很好 但我去给我的应用程序添加了另一个Xceed Datagrid,它也在使用这种风格 有没有办法不让它那样做?我可以让它只影响特定的网格吗?您可以将样式分离到一个独立的ResourceDictionary中,然后仅在所需的DataGrids中引用ResourceDictionary 示例有两个数据网格,其中只有一个具有样式集: CustomDataGridStyles.xaml: <Resourc
有没有办法不让它那样做?我可以让它只影响特定的网格吗?您可以将样式分离到一个独立的ResourceDictionary中,然后仅在所需的DataGrids中引用ResourceDictionary 示例有两个数据网格,其中只有一个具有样式集: CustomDataGridStyles.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type DataGrid}">
<Setter Property="Background" Value="Red" />
<!-- Other Style Settings -->
</Style>
</ResourceDictionary>
窗口:
<Window x:Class="SpecificControlStyle.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DataGrid Grid.Row="0">
<DataGrid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomDataGridStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</DataGrid.Resources>
</DataGrid>
<DataGrid Grid.Row="1" />
</Grid>
</Window>
您是否在XAML o代码的任何地方引用了这种样式?我不知道命名样式(具有x:Key)如何在没有被显式引用的情况下应用于任何元素。@HighCore-你说得对。我添加了将样式添加到所有网格中的所有数据行的代码。你知道我能在一个数据网格上得到什么吗?就是这样。谢谢作为其他找到这个答案的人的补充,我必须更新我的代码以引用我的网格(按名称),而不是整个窗口。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type DataGrid}">
<Setter Property="Background" Value="Red" />
<!-- Other Style Settings -->
</Style>
</ResourceDictionary>
<Window x:Class="SpecificControlStyle.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DataGrid Grid.Row="0">
<DataGrid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomDataGridStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</DataGrid.Resources>
</DataGrid>
<DataGrid Grid.Row="1" />
</Grid>
</Window>