进入网格,我尝试在所有TextBlock周围应用带有样式的边框。 我在XAML代码上没有问题,但是在外观上,当我在网格中的TextBlock周围以相同的样式应用第二个Border(Col:0行:1)时,这一个在网格中移动(Col:0行:0)。 / p>
在我的窗口中。资源:
<Style x:Key="BorderTextBlockStyle" TargetType="{x:Type Border}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="CornerRadius" Value="5"/>
<Setter Property="Grid.Column" Value="{Binding}"/>
<Setter Property="Grid.Row" Value="{Binding}"/>
</Style>
在我的窗口中:
<Grid VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Border Style="{StaticResource BorderTextBlockStyle}">
<TextBlock Grid.Column="0" Grid.Row="0" Text="Firstname" Style="{StaticResource GridTitleStyle}"/>
</Border>
<Border Style="{StaticResource BorderTextBlockStyle}">
<TextBlock Grid.Column="1" Grid.Row="0" Text="Lastname" Style="{StaticResource GridTitleStyle}"/>
</Border>
</Grid>
答案 0 :(得分:1)
您应该为Grid.Row
而非Grid.Column
设置Border
和TextBlock
<Border Grid.Column="0" Grid.Row="0" Style="{StaticResource BorderTextBlockStyle}">
<TextBlock Text="Firstname" Style="{StaticResource GridTitleStyle}"/>
</Border>
<Border Grid.Column="1" Grid.Row="0" Style="{StaticResource BorderTextBlockStyle}">
<TextBlock Text="Lastname" Style="{StaticResource GridTitleStyle}"/>
</Border>
并在“资源”中删除这些行
<Setter Property="Grid.Column" Value="{Binding}"/>
<Setter Property="Grid.Row" Value="{Binding}"/>