【问题标题】:XAML GridView entries copyable (TextBox as ItemTemplate) - IsSelected not working anymoreXAML GridView 条目可复制(TextBox 作为 ItemTemplate) - IsSelected 不再工作
【发布时间】:2015-11-17 18:27:26
【问题描述】:

我需要我的 GridView 条目被聚焦和复制,所以我制作了一个带有 TextBox 的单元格模板:

<GridViewColumn Header="Kat." Width="40">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <!-- Text to copy -->
            <TextBox Text="{Binding Category, Mode=OneWay}"/>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

现在的问题是:用户可以单击文本框并复制其内容,但只有在用户单击列之间非常小的间隙时才能更改所选行。在文本框内单击时,选定的行 (IsSelected) 不会改变。

到目前为止,有没有人遇到过同样的问题并找到了解决方案?

(我敢打赌有某种“...不是同一个可视化树”-xaml-default-problem,但仅此解释对我没有帮助。;))

【问题讨论】:

    标签: wpf xaml gridview


    【解决方案1】:

    将以下代码添加到您的 ListView:

    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin" Value="true">
                    <Setter Property="IsSelected" Value="true" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListView.ItemContainerStyle>
    

    有关详细信息,请参阅this 问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多