0
我完全不熟悉WPF。更改WPF中的选定元素
我正在MVVM模式中做一个简单的应用程序。
我有一个在其中引用模型的viewmodel。该模型包含一些我想放在组合框中的netelements。
这里是视图模型的相关部分:
public class MainWindowVM : ViewModelBase
{
private Model _model = null;
public Model Model
{
get
{
return _model;
}
}
#region ActiveElement
private NetElement _activeElement = null;
public NetElement ActiveElement
{
get
{
return _activeElement;
}
set
{
if (_activeElement != value)
{
_activeElement = value;
RaisePropertyChanged("ActiveElement");
if (ActiveElementChanged != null)
ActiveElementChanged(this, EventArgs.Empty);
}
}
}
}
我希望能够在组合框中选择一个NetElement并在activeElement设置它。
这里是我目前的XAML的相关部分:
<ItemsControl Background="White" IsTabStop="True" ItemsSource="{Binding Path=Model.RootNet.Elements}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Margin="2,6">
<Hyperlink Command="{Binding Path=I'm not able to figure out what to write here}">
<TextBlock Text="{Binding Path=Name}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
这不是一个组合框,但的TextBlocks的名单,但你可以看到它是怎么回事。
如何从视图设置ActiveElement?
这太容易了。 – SoonDead 2012-04-25 21:18:58