ListView.ItemContainerStyle IsSelected属性似乎不影响WinRT上的选择

时间:2014-04-07 06:29:59

标签: c# xaml windows-runtime

我试图在调试问题期间直接使用IsSelected set设置为true(w / o绑定)(最后我尝试使用绑定,但发现即使w / o绑定也不起作用)。

以下代码在WPF(所有选定的项目)中正常工作但在WinRT上不起作用(执行后未选择任何项目)。

这是一个错误/功能吗?

以下XAML将在WPF窗口和WinRT页面中编译..

    <ListView SelectionMode="Multiple" HorizontalAlignment="Stretch">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="IsSelected" Value="True"/>
            </Style>
        </ListView.ItemContainerStyle>
        <TextBox Width="200"/>
        <TextBox Width="200"/>
        <TextBox Width="200"/>
        <TextBox Width="200"/>
        <TextBox Width="200"/>
    </ListView>

1 个答案:

答案 0 :(得分:0)

您可以使用预定义的datatemplate为listviewItem解决此问题。希望这有帮助

<ListView SelectionMode="Multiple">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <ListViewItem  IsSelected="True" >
                            <TextBox Height="30" Width="200" ></TextBox>
                        </ListViewItem>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ListView.ItemContainerStyle>
    <TextBox />
    <TextBox/>
    <TextBox/>
    <TextBox/>
    <TextBox/>        
</ListView>