silverlight binding
I'm writing a simple silver light application and having some problems with binding issues, I'm pretty much familiar with wpf binding but here I'm must doing something wrong,
well I started by binding collection to listbox item source but no binding was done and my PropertyChanged event was allways null I tried to use simple binding of text block to text property with no results the only way to view the text is xaml hard coded text
this is my data context class:
public class 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
}
the xaml:
controls:TabItem Header="search">
controls:TabItem.ContentTemplate>
DataTemplate>
Grid>
Grid.ColumnDefinitions>
ColumnDefinition/>
/Grid.ColumnDefinitions>
ListBox Background="Gray" ItemsSource="{Binding PlayList, Mode=TwoWay,DisplayMemberPath="Name"}" >
/ListBox>
/Grid>
/DataTemplate>
/controls:TabItem.ContentTemplate>
/controls:TabItem>
the data context initialize in Loaded event (I tried in the constructor too)
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
DataContext = MediaWebControlLogic.Instance.GetContext();
}
this is how I create the object
internal DataContextItems GetContext()
{
MediaPlayerWebControl.DAL.MediaMediator mediator = new MediaPlayerWebControl.DAL.MediaMediator(); DataContextItems context= new DataContextItems();
mediator.GetPlayList(context.PlayListItemCallback);
return context;
}
the list is filled in async call I thought that it may be the problem but simple text property didn't bind too ...
any suggestions?
Thanks
Eran
Incorrect syntax: "{Binding PlayList, Mode=TwoWay,DisplayMemberPath="Name"}"
Use:
< ListBox ItemsSource="{Binding PlayList}" DisplayMemberPath="Name"/>
好吧,我发现它...的事情是,TabItem DataContext是不一样的TabControl DataContex,所以我不能只是使用“名称”属性后,将TabItem DataContext绑定到TabControl DataContext的绑定工作正常我
链接地址: http://www.djcxy.com/p/44598.html上一篇: 从代码后面的Grid.Resources获取控件属性
下一篇: silverlight绑定