ListView.ItemContainerStyle IsSelected property does not seem to affect selection on WinRT

一个人想着一个人 提交于 2019-12-23 16:42:12

问题


I was trying to use IsSelected set directly to true (w/o binding) during debugging of an issue (at the end I am trying to use binding, but have found that even w/o binding this does not work).

The following code works fine in WPF (all items selected) but does not work on WinRT (no item selected after execution).

Is this a bug/feature?

The following XAML will compile in a WPF window and in a WinRT page..

    <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:


You can solve this problem using predefined datatemplate for listviewItem.Hope this helps

<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>


来源:https://stackoverflow.com/questions/22905072/listview-itemcontainerstyle-isselected-property-does-not-seem-to-affect-selectio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!