我有一个 ListBox - ListBox.ItemTemplate - DataTemplate xaml 设置,我正在尝试将 ListBox (TextBlock) 中的文本居中。TextAlignment 属性似乎不起作用。有任何想法吗?这是我的代码:
<ListBox x:Name="listBox1" HorizontalAlignment="Left" Height="520" Margin="190,220,0,0" VerticalAlignment="Top" Width="295" SelectionChanged="listBox1_SelectionChanged" FontSize="20" FontWeight="Bold" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding name}" FontSize="25" Foreground="Black" TextAlignment="Center"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>