【发布时间】:2015-11-16 03:57:18
【问题描述】:
我有一个 ListCollectionView,其中包含一堆对象场景的项目。 Scene 中的属性之一是 Location。
当我浏览 ListCollectionView 时,我想在视图的组合框中将 Location 属性的值设置为 SelectedItem。每次我转到 ListCollectionView 中的不同项目时,我都想在组合框中将新位置显示为 SelectedItem。
我知道如何在常规的 TextBox 和 TextBlock 中进行这项工作,但在 ComboBox 中却不行。
视图模型
public ListCollectionView SceneCollectionView { get; set; }
private Scene CurrentScene
{
get { return SceneCollectionView.CurrentItem as Scene; }
set
{
SceneCollectionView.MoveCurrentTo(value);
RaisePropertyChanged();
}
}
查看
<ComboBox SelectedItem="{Binding SceneCollectionView/Location, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding AllLocations}}"/>
对于文本框,以下工作完美,但不适用于组合框
<TextBox Text="{Binding SceneCollectionView/Location, UpdateSourceTrigger=PropertyChanged}"/>
任何想法如何在 ComboBox 中为 SelectedItem 获得相同的行为。我对 C# 编码还很陌生
【问题讨论】:
-
Location属性的类型是什么? -
这是一个字符串属性
标签: c# wpf mvvm combobox selecteditem