网格中的 Avalonia 风格?
Avalonia style in Grid?
为什么我无法将此样式添加到 Grid.Resource
<Window xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="HelloAva.GreetingWindow"
Title="HelloAva">
<Window.Styles>
<Style Selector="TextBlock">
<Setter Property="FontSize" Value="30" />
</Style>
</Window.Styles>
<Grid ShowGridLines="True">
<!-- <Grid.Resources> -->
<!-- <Style Selector="TextBlock"> -->
<!-- <Setter Property="FontSize" Value="30"> -->
<!-- </Setter> -->
<!-- </Style> -->
<!-- </Grid.Resources> -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Background="LightGray" Text="Something">
</TextBlock>
<TextBlock Background="LightGray"
Text="FooBar"
Grid.Row="1" Grid.Column="1">
</TextBlock>
<TextBlock Background="LightGray"
Text="FooBar"
Grid.Row="2" Grid.Column="0">
</TextBlock>
</Grid>
</Window>
它必须添加到 Styles
集合,而不是 Resources
。
为什么我无法将此样式添加到 Grid.Resource
<Window xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="HelloAva.GreetingWindow"
Title="HelloAva">
<Window.Styles>
<Style Selector="TextBlock">
<Setter Property="FontSize" Value="30" />
</Style>
</Window.Styles>
<Grid ShowGridLines="True">
<!-- <Grid.Resources> -->
<!-- <Style Selector="TextBlock"> -->
<!-- <Setter Property="FontSize" Value="30"> -->
<!-- </Setter> -->
<!-- </Style> -->
<!-- </Grid.Resources> -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Background="LightGray" Text="Something">
</TextBlock>
<TextBlock Background="LightGray"
Text="FooBar"
Grid.Row="1" Grid.Column="1">
</TextBlock>
<TextBlock Background="LightGray"
Text="FooBar"
Grid.Row="2" Grid.Column="0">
</TextBlock>
</Grid>
</Window>
它必须添加到 Styles
集合,而不是 Resources
。