silverlight绑定
我正在写一个简单的银色应用程序,并且遇到绑定问题的一些问题,我非常熟悉wpf绑定,但是在这里我必须做出错误的事情,
以及我开始通过绑定收集到列表框项目源,但没有绑定完成,我的PropertyChanged事件是allways null我试图使用文本块的简单绑定到文本属性没有结果查看文本的唯一方法是xaml硬编码文本
这是我的数据上下文类:
公共类DataContextItems:INotifyPropertyChanged {
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#region private members
ObservableCollection<string> test;
ObservableCollection<PlayListItem> _PlayList;
PlayListItem[] _PlayListItems;
#endregion
#region public members
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<PlayListItem> PlayList
{
get { return _PlayList; }
set
{
_PlayList = value;
OnPropertyChanged("PlayList");
}
}
public PlayListItem[] PlayListItems
{
get { return _PlayListItems; }
set { _PlayListItems = value; }
}
public Action<List<PlayListItem>> PlayListItemCallback
{
get { return PlayListArrived; }
}
#endregion
#region constructor
public DataContextItems()
{
_PlayListItems = new PlayListItem[0];
_PlayList = new ObservableCollection<PlayListItem>();
}
#endregion
#region events
void PlayListArrived(List<PlayListItem> playList)
{
foreach (PlayListItem item in playList)
PlayList.Add(item);
}
#region events
}
xaml:
controls:TabItem Header =“search”>
控制:TabItem.ContentTemplate>
的DataTemplate>
网>
Grid.ColumnDefinitions>
ColumnDefinition />
/Grid.ColumnDefinitions>
ListBox Background =“Grey”ItemsSource =“{Binding PlayList,Mode = TwoWay,DisplayMemberPath =”Name“}”>
/列表框>
/网格>
/ DataTemplate中>
/controls:TabItem.ContentTemplate>
/控制:TabItem的>
数据上下文在Loaded事件中初始化(我也在构造函数中尝试过)
private void UserControl_Loaded(object sender,RoutedEventArgs e)
{
DataContext = MediaWebControlLogic.Instance.GetContext();
}
这是我如何创建对象
内部DataContextItems GetContext()
{
MediaPlayerWebControl.DAL.MediaMediator mediator = new MediaPlayerWebControl.DAL.MediaMediator(); DataContextItems context = new DataContextItems();
mediator.GetPlayList(context.PlayListItemCallback);
返回上下文;
}
该列表填写异步调用我认为这可能是问题,但简单的文本属性不绑定...
有什么建议么?
谢谢
伊兰
不正确的语法:“{绑定播放列表,模式= TwoWay,DisplayMemberPath =”名称“}”
使用:
<ListBox ItemsSource =“{Binding PlayList}”DisplayMemberPath =“Name”/>
好吧,我发现它...的事情是,TabItem DataContext是不一样的TabControl DataContex,所以我不能只是使用“名称”属性后,将TabItem DataContext绑定到TabControl DataContext的绑定工作正常我
链接地址: http://www.djcxy.com/p/44597.html上一篇: silverlight binding
下一篇: How can I specify a default property to bind to in Silverlight / WPF?