ListBoxItem 有值吗?
我想问您是否可以在 ListBoxItem
中提供将出现的字符串和要存储在数据库中的值 。 这确实是可能的:
ItemSource={Binding MyEnumColleciton}
或者
ItemSource={DynamicResource MyCollection}
等等..
但是如果你想象我有大约100个ListBoxes..我不想有这么多不同的枚举和其他ItemSource集合,我想将它直接写入ListBoxItem。
这就是我要说的:
<ListBox SelectedItem="{Binding Path=MyPath1}" Style="{StaticResource RadioButtonList}">
<ListBoxItem Content="Text1" />
<ListBoxItem Content="Text2" />
</ListBox>
<ListBox SelectedItem="{Binding Path=MyPath2}" Style="{StaticResource RadioButtonList}">
<ListBoxItem Content="Text3" />
<ListBoxItem Content="Text4" />
</ListBox>
<ListBox SelectedItem="{Binding Path=MyPath3}" Style="{StaticResource RadioButtonList}">
<ListBoxItem Content="Text5" />
<ListBoxItem Content="Text6" />
</ListBox>
... 100x
I would like you to ask if it is somehow possible to provide in the ListBoxItem
the string that will appear and the value to be stored in DB.
This is indeed possible:
ItemSource={Binding MyEnumColleciton}
or
ItemSource={DynamicResource MyCollection}
etc..
but if you image that I have about 100 ListBoxes .. I don't want to have so many different enumerations and other ItemSource collections, I want to write it directly into the ListBoxItem.
This is what I'm talking about:
<ListBox SelectedItem="{Binding Path=MyPath1}" Style="{StaticResource RadioButtonList}">
<ListBoxItem Content="Text1" />
<ListBoxItem Content="Text2" />
</ListBox>
<ListBox SelectedItem="{Binding Path=MyPath2}" Style="{StaticResource RadioButtonList}">
<ListBoxItem Content="Text3" />
<ListBoxItem Content="Text4" />
</ListBox>
<ListBox SelectedItem="{Binding Path=MyPath3}" Style="{StaticResource RadioButtonList}">
<ListBoxItem Content="Text5" />
<ListBoxItem Content="Text6" />
</ListBox>
... 100x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想出了这个:
将 DP 添加到控件的资源中:
然后:
Well I came up with this:
Add a DP into the control's resources:
And then: