MainWindow.xaml
<catel:Window x:Class="Experimetns.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:catel="http://schemas.catelproject.com"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<catel:Window.Resources>
<Style TargetType="TextBox">
<Setter Property="Foreground" Value="Red"></Setter>
</Style>
</catel:Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBox Height="30px" Width="100" Grid.Row="0" Grid.Column="0"></TextBox>
</Grid>
</catel:Window>
上面的ForeColor
设置不适用于TextBox
,而下面的方法有效
<catel:Window x:Class="Experimetns.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:catel="http://schemas.catelproject.com"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<catel:Window.Resources>
<Style TargetType="TextBox">
<Setter Property="Foreground" Value="Red"></Setter>
</Style>
</catel:Window.Resources>
<Grid>
<Grid.Resources>
<Style TargetType="TextBox">
<Setter Property="Foreground" Value="Red"></Setter>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBox Height="30px" Width="100" Grid.Row="0" Grid.Column="0"></TextBox>
</Grid>
</catel:Window>
有人有解释吗?
答案 0 :(得分:0)
这可能是由于将窗口样式注入到Catel创建的生成的窗口网格中(有关详细说明,请参见http://docs.catelproject.com/vnext/catel-mvvm/views/xaml/advanced/usercontrol-under-the-hood/)。
您可以在应用程序级别或在窗口的根内容内定义它们。您也可以研究Orchestra来帮助您了解资源字典等。