如何在 ListBoxItem WPF 中使用 space
How to utilise the space within a ListBoxItem WPF
<DataTemplate x:Key="dtTeamInGame">
<WrapPanel MaxHeight="20" >
<Label x:Name="txtPath" Content="{Binding Path = FirstName, Mode=TwoWay}" MinWidth="35" FontStretch="Expanded" ></Label>
<Label x:Name="txtPath2" Content="{Binding Path = SurName, Mode=TwoWay}" MinWidth="125" ></Label>
</WrapPanel>
</DataTemplate>
<ListBox x:Name="listBox" ItemTemplate="{DynamicResource dtTeamInGame}" HorizontalAlignment="Left" Height="100" Margin="97,206,0,0" VerticalAlignment="Top" Width="381">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDownHome" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
我的数据模板中有两个标签,我想查看标签中的所有文本,但文本被剪掉了。我想看到所有的文字,文字应该居中。我增加了标签的高度,但文本没有居中。当我将环绕面板的最大高度设置为 20 并且我需要它为 20 时出现了这个问题。我想以相同的字体大小将文本垂直居中。我已将标签的最小高度设置为 30,但文本未垂直居中。
列表框中的标签剪裁
将 Label
元素的 Padding
属性 设置为 0
或使用 TextBlocks
:
<DataTemplate x:Key="dtTeamInGame">
<WrapPanel MaxHeight="20">
<Label x:Name="txtPath" Content="FirstName" MinWidth="35" FontStretch="Expanded" Padding="0"></Label>
<Label x:Name="txtPath2" Content="Surname" MinWidth="125" Padding="0"></Label>
</WrapPanel>
</DataTemplate>
<DataTemplate x:Key="dtTeamInGame">
<WrapPanel MaxHeight="20" >
<Label x:Name="txtPath" Content="{Binding Path = FirstName, Mode=TwoWay}" MinWidth="35" FontStretch="Expanded" ></Label>
<Label x:Name="txtPath2" Content="{Binding Path = SurName, Mode=TwoWay}" MinWidth="125" ></Label>
</WrapPanel>
</DataTemplate>
<ListBox x:Name="listBox" ItemTemplate="{DynamicResource dtTeamInGame}" HorizontalAlignment="Left" Height="100" Margin="97,206,0,0" VerticalAlignment="Top" Width="381">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDownHome" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
我的数据模板中有两个标签,我想查看标签中的所有文本,但文本被剪掉了。我想看到所有的文字,文字应该居中。我增加了标签的高度,但文本没有居中。当我将环绕面板的最大高度设置为 20 并且我需要它为 20 时出现了这个问题。我想以相同的字体大小将文本垂直居中。我已将标签的最小高度设置为 30,但文本未垂直居中。
列表框中的标签剪裁
将 Label
元素的 Padding
属性 设置为 0
或使用 TextBlocks
:
<DataTemplate x:Key="dtTeamInGame">
<WrapPanel MaxHeight="20">
<Label x:Name="txtPath" Content="FirstName" MinWidth="35" FontStretch="Expanded" Padding="0"></Label>
<Label x:Name="txtPath2" Content="Surname" MinWidth="125" Padding="0"></Label>
</WrapPanel>
</DataTemplate>