绑定与 ItemPanel 的行为很奇怪,没有则正常
以下代码显示 {Binding text}
并且 Sprites 的依赖属性不会运行文本运行的 propertyvaluechanged,但不会运行 sprites。
<ItemsControl x:Name="AnswerListBox" ItemsSource="{Binding Answers}" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:spriteRadioButton Text="{Binding text}" Sprites="{Binding Path=DataContext.UISprites, ElementName=questionField}" GroupName="{Binding Path=DataContext.QuestionTitle, ElementName=questionField}" IsChecked="{Binding selected}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
如果我不使用 itemspaneltemplate 那么属性将按预期工作。
The following code on displays the {Binding text}
and the dependency property for Sprites does not run the propertyvaluechanged for text runs but not for sprites.
<ItemsControl x:Name="AnswerListBox" ItemsSource="{Binding Answers}" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:spriteRadioButton Text="{Binding text}" Sprites="{Binding Path=DataContext.UISprites, ElementName=questionField}" GroupName="{Binding Path=DataContext.QuestionTitle, ElementName=questionField}" IsChecked="{Binding selected}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
if i don't use an itemspaneltemplate then the properties work as expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前您正在使用默认的“OneWay”绑定机制。这意味着您的对象可以更新 UI,但 UI 无法更新对象。
您的绑定应使用“TwoWay”绑定,以便允许 UI 通知对象发生更改:
请记住,这些更改将更新您的 Answers 对象。如果您想更改 Answers 对象本身,也需要将其标记为 TwoWay 绑定。
At the moment you're using the default "OneWay" binding mechanism. This means that your object can update the UI but the UI cannot update the object.
Your binding should use "TwoWay" binding in order to allow the UI to notify the object of changes:
Keep in mind, these changes will update your Answers object. If you want to change the Answers object itself this too will need to be marked as TwoWay binding as well.