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