【发布时间】:2012-03-03 00:02:45
【问题描述】:
我的绑定:
祖先的 DataContext :
detailsPanel.DataContext = client
项目控制:
<ItemsControl
x:Name="PlayersItemsControl"
ItemsSource="{Binding Peers}"
ItemsPanel="{StaticResource PlayersItemsControlPanel}"
ItemTemplate="{StaticResource PlayersItemsControlTemplate}">
</ItemsControl>
项目模板
<DataTemplate x:Key="PlayersItemsControlTemplate" >
<Button Content="{Binding Name}" IsEnabled="{Binding InConversation,Converter={StaticResource MyStatusToButtonEnableConverter}}"> </Button>
</DataTemplate>
物品来源:
public class Client : INotifyPropertyChanged
{
// the itemscontrol items source
private ObservableCollection<Player> peers;
public ObservableCollection<Player> Peers
{
get
{
if (peers == null)
peers = new ObservableCollection<Player>();
return peers;
}
}
// the property i wan't to bind to IsEnabled Property of the Button
private bool inConversation;
public bool InConversation
{
get {return inConversation; }
set
{
inConversation = value;
if(PropertyChanged != null)
PropertyChanged(this,new PropertyChangedEventArgs("InConversation"));
}
}
}
项目绑定到 Peers 集合,每个文本块绑定到当前 Peer 的名称。
我遇到的问题是我需要将每个按钮(项目)绑定到客户端中的不同属性 集合中当前 Peer 之外的“InConversation”。
这样的绑定怎么做?
【问题讨论】:
标签: c# wpf data-binding