你不需要任何東西只是你使用的數據。您應該對控件的外觀感興趣。 (你不希望被加上對照)
<ListBox ItemsSource="{Binding MyItems}" SelectedItem="{Binding MyItem}" />
可能是:
<SexyWoman Legs="{Binding MyItems}" Ass="{Binding MyItem}" />
,它也能發揮作用。
列表框有這個類作爲一個DataContext:
class DummyClass : INotifyPropertyChanged
{
private MyItem _myItem;
public MyItem MyItem
{
get { return _myItem; }
set { _myItem = value; NotifyPropertyChanged("MyItem"); }
}
private IEnumerable<MyItem> _myItems;
public IEnumerable<MyItem> MyItems
{
get { return _myItems; }
}
public void FillWithItems()
{
/* Some logic */
_myItems = ...
NotifyPropertyChanged("MyItems");
/* This automatically selects the first element */
MyItem = _myItems.FirstOrDefault();
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string value)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(value));
}
}
#endregion
}
這就是我已經和它不工作<列表框高度= 「67」 的HorizontalAlignment =「左「Name =」lb「VerticalAlignment =」Top「Width =」49「Visibility =」Collapsed「Margin =」12,32,0,0「ListBoxItem.Selected =」lbSelected「SelectedIndex =」0「/> – gumenimeda
How to you you填充你的列表?我的意思是你使用綁定? –
我編輯了我的回覆 –