Xaml:项目源绑定 +回退值
我有一个在 Itemssource-Property 上带有数据绑定的列表选择器。绑定效果很好。现在我想定义一个 FallbackValue。我的问题是,FallbackValue 被解释为列表:{'S','t','a','n','d','a','r','d'},而不是单个项目“标准”。我正在寻找解决这个问题的方法。有什么想法吗?
<toolkit:ListPicker x:Name="listPicker" ExpansionMode="FullScreenOnly" ItemsSource="{Binding Profilelist, ElementName=userControl, FallbackValue='Standard'}" SelectedIndex="0" />
I've got a Listpicker with a DataBinding on the Itemssource-Property. Binding works fine. Now I want to define a FallbackValue. My problem is, that the FallbackValue is interpreted as a list: {'S','t','a','n','d','a','r','d'}, not as a single item 'Standard'. I'm looking for a solution to solve this problem. Any idea?
<toolkit:ListPicker x:Name="listPicker" ExpansionMode="FullScreenOnly" ItemsSource="{Binding Profilelist, ElementName=userControl, FallbackValue='Standard'}" SelectedIndex="0" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回退行为是正确的,因为目标需要一个数组(以及一个可用作字符数组的字符串)。没有简单的方法来指定后备数组。
我建议绑定到 ViewModel 列表,而不是直接绑定到其他控件,这样您就可以在列表中指定您想要的任何默认值。它确实意味着 ViewModel 上的额外绑定和属性(或隐藏代码...yuk),但元素绑定并未设计为具有后备数组,只有单个值。
如果您可以提供更多代码/Xaml,我将能够更具体。
The fallback behaviour is correct as the target expects an array (and a string an usable as an array of chars). There is no easy way to specify an array for the fallback.
I would suggest binding to a ViewModel list, instead of directly to the other control, so you can specify whatever default you want in the list. It does mean an extra binding and a property on your ViewModel (or code-behind... yuk) but element binding is not designed to have a fallback array, only single values.
If you can provide more code/Xaml I will be able to be more specific.