Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何利用ListBoxItem WPF中的空间_Wpf_Listbox_Datatemplate - Fatal编程技术网

如何利用ListBoxItem WPF中的空间

如何利用ListBoxItem WPF中的空间,wpf,listbox,datatemplate,Wpf,Listbox,Datatemplate,我的数据模板中有两个标签,我希望看到标签中的所有文本,但文本被剪掉了。我想看到所有的文字,文字应该居中。我增加了标签的高度,但文本没有居中。当我将“包裹面板最大高度”(wrap panel max height)设置为20时出现此问题,我需要将其设置为20。我想以相同的字体大小垂直居中文本。我已将标签的最小高度设置为30,但文本没有垂直居中 在列表框中剪切标签 将标签元素的Padding属性设置为0或使用TextBlocks: <DataTemplate x:Key="dtTeamInGa

我的数据模板中有两个标签,我希望看到标签中的所有文本,但文本被剪掉了。我想看到所有的文字,文字应该居中。我增加了标签的高度,但文本没有居中。当我将“包裹面板最大高度”(wrap panel max height)设置为20时出现此问题,我需要将其设置为20。我想以相同的字体大小垂直居中文本。我已将标签的最小高度设置为30,但文本没有垂直居中

在列表框中剪切标签

将标签元素的Padding属性设置为0或使用TextBlocks:

<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>
<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>