【发布时间】:2017-12-30 01:20:30
【问题描述】:
我有这个:
<Border Background="Gray">
<TextBlock x:Name="Text"
Text="{Binding Name}"
Margin="0, 5"
FontSize="16"/>
</Border>
看起来像这样:(其中三个)
我希望它看起来像这样:
(边框延伸到空间的尽头 + 对边框高度的一些控制。)
附注我不必使用边框,任何可以达到相同效果的东西都可以。
更新:这是 ListBoxItem 的 DataTemplate 的一部分。它是这样定义的:
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Border>
<TextBlock x:Name="Text"
Text="{Binding Name}"
Margin="0, 5"
FontSize="16"/>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
我尝试将 HorizontalAlignment 设置为“Stretch”,但没有成功。有什么想法吗?
【问题讨论】:
-
HorizontalAlignment="Stretch"(在边框上)
-
可以显示更多代码吗?
-
你在哪里放置边框?在 ListBox 的 ItemTemplate 中?
-
只是好奇为什么不为 TextBox 设置背景?
-
@FoggyFinder 因为也许我想要的不仅仅是文本。