Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.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# 通用应用程序中的动态表_C#_Wpf_Mvvm_Win Universal App_Stackpanel - Fatal编程技术网

C# 通用应用程序中的动态表

C# 通用应用程序中的动态表,c#,wpf,mvvm,win-universal-app,stackpanel,C#,Wpf,Mvvm,Win Universal App,Stackpanel,我正在为windows phone 8.1/windows 8.1开发通用应用程序。我使用的是MVVM模式。我有一个表,其中包含绑定到视图模型中源代码的stackpanel的动态数量。一个stackpanel是表中的一行。如何使堆栈面板中的项目具有相同的宽度?我知道IsSharedSizeScope,但这在universal app的网格中不可用 <ItemsControl Grid.Column="1" HorizontalAlignment="Stretch"

我正在为windows phone 8.1/windows 8.1开发通用应用程序。我使用的是MVVM模式。我有一个表,其中包含绑定到视图模型中源代码的stackpanel的动态数量。一个stackpanel是表中的一行。如何使堆栈面板中的项目具有相同的宽度?我知道
IsSharedSizeScope
,但这在universal app的网格中不可用

<ItemsControl Grid.Column="1" HorizontalAlignment="Stretch" 
            ItemsSource="{Binding PowerMaxiTableSource0, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Border Background="{Binding IsEnabled, Converter={StaticResource BackgroundConverter}}">
                    <TextBlock Text="{Binding Text0}" />
                </Border>
                <Border Background="{Binding IsEnabled, Converter={StaticResource BackgroundConverter}}">
                    <TextBlock Text="{Binding Text1}" />
                </Border>
                <Border Background="{Binding IsEnabled, Converter={StaticResource BackgroundConverter}}">
                    <TextBlock Text="{Binding Text2}" />
                </Border>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Vertical" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

因为这是一张桌子,我试着用网格代替stackpanels,但我没能让它工作。我试过这个方法。但我最终得到了聚集在第0行、第0列的项目,即使绑定属性中的值正确


任何帮助都将不胜感激(即使是网格解决方案)。

StackPanel
s的宽度由其子级驱动。
StackPanel
中似乎有3个子项,这意味着它们不是动态生成的。您声明只更改堆栈面板的数量。如果您不反对
网格
使用而不是
堆栈面板
,则以下代码将起作用,因为
网格
将自动拉伸(采用所有允许的宽度),并在您创建宽度指定为百分比的列时动态向下延伸该宽度到其子级:

<ItemsControl HorizontalAlignment="Stretch">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="33*"/>
                        <ColumnDefinition Width="33*"/>
                        <ColumnDefinition Width="33*"/>
                    </Grid.ColumnDefinitions>
                    <Border Grid.Column="0" Background="{Binding IsEnabled, Converter={StaticResource BackgroundConverter}}">
                        <TextBlock Text="{Binding Text0}" />
                    </Border>
                    <Border Grid.Column="1" Background="{Binding IsEnabled, Converter={StaticResource BackgroundConverter}}">
                        <TextBlock Text="{Binding Text1}" />
                    </Border>
                    <Border Grid.Column="2" Background="{Binding IsEnabled, Converter={StaticResource BackgroundConverter}}">
                        <TextBlock Text="{Binding Text2}" />
                    </Border>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>


是否可以为所有文本块指定一个固定的宽度并使用TextTrimming属性?如果没有固定的宽度会更好,因为我需要覆盖许多不同的屏幕大小,但我看不到任何其他方法。谢谢,它工作得近乎完美。然而,在某些单元格中,宽度有时会变宽,但这在我的情况下是可以接受的,谢谢。