我试图将代码隐藏中的对象移动到XAML中的资源。
我想移动这些对象
public partial class MainView : Window
{
public EventAggregator IEA;
public OrderViewModel order { get; set; }
public MenuViewModel menu { get; set; }
public MainView()
{
InitializeComponent();
this.DataContext = this;
IEA = new EventAggregator();
order = new OrderViewModel(IEA);
menu = new MenuViewModel(IEA);
}
}
到这里
<Window.Resources>
<ObjectDataProvider x:Key="IEA" d:IsDataSource="True" ObjectType="{x:Type Prism.Events:EventAggregator}"/>
<ObjectDataProvider x:Key="OVM" d:IsDataSource="True" ObjectType="{x:Type local:OrderViewModel}">
<ObjectDataProvider.ConstructorParameters>
<StaticResource ResourceKey="IEM"/>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="MVM" d:IsDataSource="True" ObjectType="{x:Type local:MenuViewModel}">
<ObjectDataProvider.ConstructorParameters>
<StaticResource ResourceKey="IEM"/>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
</Window.Resources>
但显然我错误地引用了Prism的EventAggregator类,因为我收到以下错误:
Error: 'Prism.Events' is an undeclared namespace
答案 0 :(得分:2)
对我而言,这有效:
xmlns:prismEvents="clr-namespace:Prism.Events;assembly=Prism"
<ObjectDataProvider x:Key="IEA"
d:IsDataSource="True"
ObjectType="{x:Type prismEvents:EventAggregator}" />