你不需要任何东西只是你使用的数据。您应该对控件的外观感兴趣。 (你不希望被加上对照)
<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填充你的列表?我的意思是你使用绑定? –
我编辑了我的回复 –