gpt4 book ai didi

c# - Popup 中的 WPF ListBox 在 PopupClose 上设置 null SelectedItem

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:37 25 4
gpt4 key购买 nike

我有一个 WPF 弹出窗口,其结构如下(删除了一些敏感内容)...

<Popup>
<Border>
<StackPanel>

<ListBox
ItemSource="{Binding X}"
SelectedItem="{Binding Y}"
IsSynchronizedWithCurrentItem="True"/>

<Separator/>

<MenuItem Command="{Binding Path=EditModeCommand}"/>

</StackPanel>
</Border>
</Popup>

ListBox 按预期工作,列表从绑定(bind)中填充,并且所选项目正确反馈到集合。

但是,当 MenuItem 触发其命令时,SelectedItem 绑定(bind)也会触发,将 SelectedItem 设置为 null。当列表框不是点击焦点时,有没有办法保留 SelectedItem?

最佳答案

关于c# - Popup 中的 WPF ListBox 在 PopupClose 上设置 null SelectedItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4957578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com