ItemsControl,绑定文本从末尾开始减少

时间:2014-04-06 16:52:46

标签: c# winrt-xaml windows-8.1

我正在努力赢得8.1app。我有一个datatemplate

 <DataTemplate x:Key="RadioOptionDataTemplate">
        <Grid HorizontalAlignment="Left">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Margin="0 0 0 15">
                <Run Text="{Binding name}"/><Run Text=":"/>
            </TextBlock>
            <ItemsControl Grid.Row="1" ItemsSource="{Binding GetOptions}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <RadioButton Content="{Binding}" Margin="0 0 10 10" IsChecked="True"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <ItemsWrapGrid Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </Grid>
    </DataTemplate>

显示此类数据

enter image description here

现在,如果你看到文字从右端减少了。如果我设置单选按钮的静态内容比一切看起来都好。

我想知道为什么在绑定的情况下会发生这种情况。

1 个答案:

答案 0 :(得分:0)

ItemsControl项目的宽度是根据它的第一项需要的大小来计算的。在你的代码中没有大米&#39;是你的第一个项目文本&amp;第二和第三项文本比第一项文本长。那是因为文本包装。

如果您设置的第一个项目文字较长,则所有其他项目都适合视图&amp;文字不会被切断。

您可以使用文本换行作为避免文本截断的一种方法。或者您必须创建一个具有可变项宽度的Items控件。

请检查以下链接,以创建具有可变项目宽度的网格视图

How to Display Gridview items with variable width in Window 8?

由于