首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ListBox CurrentItem / SelectedItem

ListBox CurrentItem / SelectedItem
EN

Stack Overflow用户
提问于 2018-01-03 07:41:47
回答 1查看 606关注 0票数 0

我正在使用一个定制的ListBoxItem,它是这样构建的

代码语言:javascript
复制
<Style x:Key="MyListBoxItem"  TargetType="{x:Type ListBoxItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                <Border>
                    <Border>
                        <ContentPresenter />
                    </Border>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

它是我需要的编辑控件修改的基本结构,如下所示

代码语言:javascript
复制
<Style x:Key="MyListBoxItemText"  TargetType="{x:Type ListBoxItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                <ListBoxItem Style="{DynamicResource MyListBoxItem}">
                    <TextBox  />
                </ListBoxItem>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

使用的ListBoxItem用于ListBox的已使用ItemsSource的特定记录,由StyleSelector选择。

我需要的是访问ListBoxItem的可能性,这是目前关注的焦点。我试过以下几种方法

  • 将ListBox的IsSyncronizedWithCurrentItem-属性设置为true
  • 尝试获取SelectionChanged事件的ListBox
  • 监视IsSelected属性的ListBoxItem
  • 用ListBoxItem的基本样式定义(多个)触发器
  • 设置一个EventSetter

有人能帮我吗?

提前谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-01-03 11:05:44

好吧,以下是我的尝试:

代码语言:javascript
复制
<ControlTemplate.Triggers>
    <DataTrigger  Binding="{Binding Selector.IsSelected}" Value="True">
        <Setter Property="Background" Value="Salmon" />
    </DataTrigger>
</ControlTemplate.Triggers>


<ControlTemplate.Triggers>
    <DataTrigger  Binding="{Binding ListBoxItem.IsSelected}" Value="True">
        <Setter Property="Background" Value="Salmon" />
    </DataTrigger>
</ControlTemplate.Triggers>


<ControlTemplate.Triggers>
    <DataTrigger  Binding="{Binding IsSelected}" Value="True">
        <Setter Property="Background" Value="Salmon" />
    </DataTrigger>
</ControlTemplate.Triggers>

在ListBox的样式中,IsSyncronizedWithCurrentItem属性设置为true。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48073134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档