Silverlight ItemsControl 和 ComboBox
我正在清理这个问题,并将放入一个对我有意义的示例......希望对你也有意义......
所以可以说我有一个 Items 控件。此控件绑定到 NBA 篮球队(湖人队、热火队、尼克斯队...等)的可观察集合。在这个可观察的 NBATeams 集合中,我有一个属性 favoritePlayer。我有一个数据模板,列出了项目控件内部的外观。我有一个显示团队名称的文本框。 (这可能/应该只读......现在不是)但它显示球队名称......洛杉矶湖人队。我的项目控件中的第二个项目是一个组合框。这个组合框最终将显示每支球队中我最喜欢的球员。
组合框中的项目源来自我拥有的查找值。它显示团队中的所有人员,并且此组合框中的显示成员路径是“DisplayText”...我需要显示此组合框中我选择的项目。所以如果我最喜欢的球员是科比·布莱恩特,组合框应该显示这个。
<telerik:RadComboBox Grid.Row="0" Grid.Column="9" Width="150" EmptyText="--Select Player--"
ItemsSource="{Binding PlayerList}"
SelectedItem="{Binding FavoritePlayer, Mode=TwoWay}"
DisplayMemberPath="DisplayText" HorizontalAlignment="Left"></telerik:RadComboBox>
我习惯于在列表框中只包含文本块,然后当从该列表框中选择一个项目时,我使用该选定的项目来绑定位于列表框外部的组合框。现在我实际上在列表框中有组合框(现在是 ItemsControl)。所以我想知道从 ItemsControl 中绑定组合框的最佳方法
我最初只是遇到让玩家显示在组合框中的问题..但我通过执行下面的代码解决了这个问题。
我发现我的第一个问题只是从项目控件中将项目源绑定到组合框。
我必须将绑定设置为如下所示。
ItemsSource="{Binding DataContext.PlayerList, ElementName=ItemsControlNBATeams}"
所以我必须设置项目控件的名称并在元素名称中使用它,并将 path = 设置为 DataContext.PlayerList。现在,这将显示我的组合框中的项目。它不做的是设置我的组合框中的选定项目。
Im cleaning up this question and going to put in an example that makes sense to me..hopefully for you too...
so lets say i have an Items control. This control is bound to an observable collection of NBA Basketball teams (Lakers, Heat, Knicks...ect). In this observable collection of NBATeams I have a property of FavoritePlayer. I have a datatemplate that lays out how this is going to look inside the Items Control. I have a textbox which displays the team name. (this could be/should be read only..its not now) but it displays the team name.. LA Lakers. the second item in my items control is a combobox. this combo box will ultimately display my favorite player on each team.
The itemssource on the combobox is from a lookup value i have. It displays all the people on the team and the displaymemberpath on this combobox is "DisplayText"...I need my selected item on this combobox to be shown. so if my favorite player is Kobe Bryant the combo box should display this.
<telerik:RadComboBox Grid.Row="0" Grid.Column="9" Width="150" EmptyText="--Select Player--"
ItemsSource="{Binding PlayerList}"
SelectedItem="{Binding FavoritePlayer, Mode=TwoWay}"
DisplayMemberPath="DisplayText" HorizontalAlignment="Left"></telerik:RadComboBox>
I am used to just having textblocks in a listbox and then when an item is selected from within that listbox i use that selected item to bind my comboboxes that live outside of my listbox. Now i actually have the combobox in the listbox(ItemsControl now). So Im wondering the best way to bind the combobox from within an ItemsControl
I initially was just having issues getting the players to show up in the combobox..but I solved that by doing the code below.
I found my first issue of just binding the items source to the combo box from within an items control.
I had to set the bindings to look like this.
ItemsSource="{Binding DataContext.PlayerList, ElementName=ItemsControlNBATeams}"
so i had to set the name of the items control and use that in the element name and set the path = to DataContext.PlayerList. this now brings up the items in my combo box..what it doesnt do is set the selecteditem of my combo box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太清楚您要问的问题,但这是否回答了您的问题
Not very clear about your you are asking but does this answer your question