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

标签 c# xaml windows-runtime

我试图在调试问题期间将 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>

关于c# - ListView.ItemContainerStyle IsSelected 属性似乎不影响 WinRT 上的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22905072/

相关文章:

c# - 检索 MIME 类型或文件扩展名的文件关联图标

visual-studio - XAML 文件 .editorconfig 规则

c# - 尝试引用用户控件时出现错误 "The name does not exist in the current context"

windows-8 - 在 WinRT 中增量加载数据组时,如何设置它们的样式?

winforms - Windows 8 密码框占位符

c# - 如何显示图像并将其添加为电子邮件的附件

c# - 将数组拆分为另一个数组

c# - 我如何写一个 "events per second"PerformanceCounter?

xaml - windows phone 8.1 ComboBox 当项目数量更多时,将多个项目显示为已选择

windows - NavigationView中的UWP ListView,仅呈现第一个子级