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, тогда как ниже работает
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>
У кого-нибудь есть объяснение?
Это может быть вызвано тем, что стили окна внедряются в сгенерированную сетку окон, которую создает Catel (подробное объяснение см. http://docs.catelproject.com/vnext/catel-mvvm/views/xaml/advanced/usercontrol-under-the-hood/).
Вы можете определить их в приложении.уровень или внутри корневого содержимого окна.Вы также можете обратиться к Orchestra , чтобы помочь вам со словарями ресурсов и т. Д.