Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.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
C# ListBoxItem在ListBox中不拉伸_C#_Xaml_Silverlight_Windows Phone 8 - Fatal编程技术网

C# ListBoxItem在ListBox中不拉伸

C# ListBoxItem在ListBox中不拉伸,c#,xaml,silverlight,windows-phone-8,C#,Xaml,Silverlight,Windows Phone 8,我正在为Windows Phone 8(silverlight)创建一个应用程序。我想在列表框中以两列显示数据。本文中是一个带有代码的演示项目。以下是输出的基本代码: <ListBox x:Name="ItemsListBox"> <ListBox.ItemTemplate> <DataTemplate> <ItemsControl ItemTemplate="{StaticResource ItemDataTemplate}"

我正在为Windows Phone 8(silverlight)创建一个应用程序。我想在列表框中以两列显示数据。本文中是一个带有代码的演示项目。以下是输出的基本代码:

<ListBox x:Name="ItemsListBox">
<ListBox.ItemTemplate>
    <DataTemplate>
        <ItemsControl ItemTemplate="{StaticResource ItemDataTemplate}" ItemsSource="{Binding}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </DataTemplate>
</ListBox.ItemTemplate>

它可以工作,但数据不会拉伸,右边是自由空间。

我尝试了很多选择

<ListBox...>
<ListBox.Resources>
    <Style TargetType="ListBoxItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</ListBox.Resources>

插入的水平对齐=“拉伸”

但它们不起作用。告诉我如何拉伸数据宽度?我需要让每列占据总宽度的一半

这是我的数据模板代码

<DataTemplate x:Key="ItemDataTemplate" >


        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="4*"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>




            <Button Grid.Column="1" Margin="5" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="4*"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Name}"  />
                    <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding AddInfo}"  />
                </Grid>
            </Button>

        </Grid>


</DataTemplate>

在数据模板中,应为垂直拉伸添加Height=“100%”或为水平拉伸添加weidth=“100%” 这在textblock中

</Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Name}" Height="//some vale in decimal" Widht="//some vale in decimal" />
                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding AddInfo}" Height="//some vale in decimal" Widht="//some vale in decimal" />
            </Grid>


我尝试过,但这不起作用-右边是免费的space@EugenePodskal
UniformGrid
在Silverlight/wp中不存在您是否也可以发布“ItemDataTemplate”的标记?我们需要看看你是如何设置的。我在问题中添加了CodeItemDataTemplate我确实需要一个不固定的宽度