如何将 TextBlock 置于 GridViewColumn 中心? (包括示例 xaml)
<Window x:Class="EffectsWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<ListView ItemsSource="{Binding EffectsViewModel.Effects}">
<ListView.View>
<GridView>
<GridViewColumn Width="200" Header="Effects">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center"
Text="{Binding Name}"
TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Window>
Effect
只是一个具有返回字符串的 Name 属性的类型,但文本仍然没有在其单元格内居中。
关于如何修复它有什么想法吗?
<Window x:Class="EffectsWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<ListView ItemsSource="{Binding EffectsViewModel.Effects}">
<ListView.View>
<GridView>
<GridViewColumn Width="200" Header="Effects">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center"
Text="{Binding Name}"
TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Window>
Effect
is just a type has a Name property that returns a string, but the text is still not centered inside its cell.
Any ideas on how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以拉伸
ItemContainerStyle
的HorizontalContentAlignment
更新
您应该能够将交替的行颜色与
HorizontalContentAlignment
结合起来,如下所示。我尝试了一下,似乎有效You can Stretch the
HorizontalContentAlignment
forItemContainerStyle
Update
You should be able to combine the alternating row colors with
HorizontalContentAlignment
like this. I tried it and it seems to be working尝试使用 snoop 之类的应用程序来直观地检查应用程序的属性,您可以看到哪些地方没有对齐,例如你期望的。
Try using an app like snoop to visually inspect the properties of your app and you can see where things are not aligning like you expect.