Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.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
WPF-Usercontrol作为ListItemTemplate不填充listbox宽度_Wpf_Vb.net_User Controls_Autosize - Fatal编程技术网

WPF-Usercontrol作为ListItemTemplate不填充listbox宽度

WPF-Usercontrol作为ListItemTemplate不填充listbox宽度,wpf,vb.net,user-controls,autosize,Wpf,Vb.net,User Controls,Autosize,只是想让我的头脑清醒一下。我有一个usercontrol,我正在使用它作为列表框中项目的模板,但是无论我尝试什么,usercontrol的宽度总是缩小到最小大小,但我希望它填充可用的宽度。我在这里发现了一个类似的查询,但它只与一个不在列表框中的usercontrol相关,并且提出的解决方案不适用于这里 My UserControl定义为: <UserControl x:Class="uReportItem" xmlns="http://schemas.microsoft.

只是想让我的头脑清醒一下。我有一个usercontrol,我正在使用它作为列表框中项目的模板,但是无论我尝试什么,usercontrol的宽度总是缩小到最小大小,但我希望它填充可用的宽度。我在这里发现了一个类似的查询,但它只与一个不在列表框中的usercontrol相关,并且提出的解决方案不适用于这里

My UserControl定义为:

<UserControl x:Class="uReportItem"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="60" d:DesignWidth="300">
<Grid >
    <Border CornerRadius="3,3,3,3" BorderBrush="#0074BA" BorderThickness="1" Background="#00D6F9" Margin="0">
        <DockPanel Margin="3,3,3,3">
            <Grid Height="Auto">
                <!-- Grid Definition-->
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <!-- Content -->

                <!-- Top Row-->
                <Button Grid.RowSpan="2">Delete</Button>
                <StackPanel Orientation="Horizontal" Grid.Column="1">
                    <Label x:Name="Heading" Content="{Binding Heading}" FontSize="14" FontWeight="bold"></Label>
                    <Label x:Name="Subheading" Content="{Binding SubHeading}" FontSize="14"></Label>
                </StackPanel>
                <Button Grid.Column="2">Blah</Button>


                <!-- Second Row-->
                <Label Grid.Row="1" Grid.Column="1" x:Name="Comments">Comments</Label>
                <Button Grid.Column="2">Blah</Button>
            </Grid>
        </DockPanel>
    </Border>
</Grid>

删除
废话
评论
废话

窗口上的实现是:

<Window x:Class="vReport"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RecorderUI"
Title="vReport" Height="300" Width="300" Background="#00BCF0">

<Window.Resources>
    <DataTemplate x:Key="Record" DataType="ListItem">
        <Grid>
            <local:uReportItem></local:uReportItem>
        </Grid>
    </DataTemplate>
    <Style TargetType="ListBoxItem">
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
    </Style>
</Window.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>

    <local:uReport Margin="5" Grid.Row="0"></local:uReport>

    <Border Grid.Row="1" BorderBrush="#0074BA" CornerRadius="3">
        <ListBox Margin="5" Background="#00D6F9" BorderBrush="#0074BA" x:Name="ListRecords" ItemsSource="{Binding Items}" ItemTemplate ="{StaticResource Record}"></ListBox>
    </Border>

    <TextBlock Grid.Row="2" x:Name="SelectedItem" Text="{Binding Path=SelectedItem.Heading, Mode=TwoWay}"></TextBlock>
</Grid>


有什么想法吗?

尝试将
列表框上的
水平内容对齐设置为
拉伸

<ListBox Margin="5" Background="#00D6F9" BorderBrush="#0074BA" x:Name="ListRecords" ItemsSource="{Binding Items}" ItemTemplate ="{StaticResource Record}" HorizontalContentAlignment="Stretch"></ListBox>

Superb-在使用常规windows窗体大约20年后,学习WPF是一项艰苦的工作!