8,735
社区成员
发帖
与我相关
我的任务
分享
<ComboBox Name="cbCategory" Width="120" Margin="5" ItemsSource="{Binding Path=AllCategories}" DisplayMemberPath="Name" />
public class ContentBrowserViewModel
{
private ICollectionView allCategories;
private ObservableCollection<string> categories { get; set; }
public ContentBrowserViewModel()
{
categories = new ObservableCollection<string>(Enum.GetNames(typeof(ContentCategory)));
this.allCategories = CollectionViewSource.GetDefaultView(categories);
this.allCategories.CurrentChanged += new EventHandler(allCategories_CurrentChanged);
}
void allCategories_CurrentChanged(object sender, EventArgs e)
{
MessageBox.Show(this.allCategories.CurrentItem.ToString());
}
public ICollectionView AllCategories { get { return this.allCategories; } }
}
<ComboBox Name="cbCategory" ItemsSource="{Binding Path=AllCategories}" />