[英]WPF - Why is my property not being updated?
Here's some code: 这是一些代码:
<ListBox
MaxWidth="468"
SelectionMode="Extended"
ItemsSource="{Binding Visitors, Mode=TwoWay}">
<ListBox.ItemContainerStyle>
<Style TargetType={x:Type ListBoxItem}>
<Setter Property="IsSelected" Value="{Binding VisitorSelected, Mode=TwoWay}" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
I need Visitors
to be updated (at the source) whenever a visitor is selected. 每当选择Visitors
,我都需要更新Visitors
(从源头开始)。 For some reason, What I have doesn't work. 由于某种原因,我所拥有的不起作用。 I'm racking my brain, but I can't think of a way around this. 我正在绞尽脑汁,但是我想不出办法。 Ideas? 有想法吗?
EDIT: Sorry, I accidentally had a duplicated property in there, which I removed. 编辑:对不起,我不小心在其中有重复的属性,因此将其删除。 Also, let me clarify something: VisitorSelected
IS getting updated. 另外,让我澄清一下: VisitorSelected
IS正在更新。 However it's not doing me much good, because I need to be notified in the view model containing Visitors
- not where VisitorSelected
is defined. 但是,这对我没有多大帮助,因为需要在包含Visitors
的视图模型中通知我-而不是在定义VisitorSelected
位置。 I hope this makes sense 我希望这是有道理的
I ended up adding an Action
parameter to the visitor item type, then calling that when VisitorSelected
is set. 最后,我向访问者项目类型添加了一个Action
参数,然后在设置VisitorSelected
时VisitorSelected
进行了调用。 The Action
is passed in by the view model. Action
由视图模型传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.