我试图在调试问题期间将 IsSelected 直接设置为 true(没有绑定(bind))(最后我尝试使用绑定(bind),但发现即使没有绑定(bind)也不起作用)。
以下代码在 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>
请您参考如下方法:
您可以使用 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>