I m trying to put Prism (just for CompositeUI) and MVVM Light Toolkit (for MVVM architecture =D) working together, but I m getting some troubles with the Light ViewModelLocator. When we use the locator into a "simple" WPF application, we can use an application resource on App.xaml, like this:
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</Application.Resources>
但是,当我们使用棱镜时,我们的商法属于模块项目,而且没有上诉程序,那么我试图将这一资源放在观点资源中:
<Window.Resources>
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</ResourceDictionary>
</Window.Resources>
这只是偏离了我的设计模式(也是时间的)错误,但《观点》却出现在分配给它的区域内。
Somebody already tried to do something like this? Is it possible to put Prism and MVVM Light working together?
这是我的“完整”法典:
(Light.xaml)
<Window x:Class="TryERP2.Financeiro.View.ViewLight"
... a lot of NS ...
mc:Ignorable="d"
xmlns:vm="clr-namespace:TryERP2.Financeiro.ViewModel"
d:DesignHeight="150" d:DesignWidth="245" SizeToContent="WidthAndHeight">
<Window.Resources>
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</ResourceDictionary>
</Window.Resources>
<Grid DataContext="{Binding Light, Source={StaticResource Locator}}">
<Button Content="{Binding MyButtonText}" HorizontalAlignment="Stretch" Name="button1" VerticalAlignment="Stretch" />
</Grid>
</Window>
ViewLightModel.cs:
public class ViewLightModel : ViewModelBase
{
public ViewLightModel()
{ }
public const string MyButtonTextPropertyName = "MyButtonText";
private string _myButtonText = "Button Text";
public string MyButtonText
{
get
{ return _myButtonText; }
set
{
if (_myButtonText == value)
{ return; }
_myButtonText = value;
RaisePropertyChanged(MyButtonTextPropertyName);
}
}
}
Financeiro.cs (The module initializer class ... Partially shown ... Just where I register and "invoke" the views):
var container = ServiceLocator.Current.GetInstance<IUnityContainer>();
container.RegisterType<Object, ViewLight>("ViewLight");
var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
var main = new Uri("ViewLight", UriKind.Relative);
regionManager.RequestNavigate("Desktop", main);
“热”甚微电离层电离层电离层电离层电离层电离层电离层电离层电离层。 该档案有这一结构:
<Application x:Class="TryERP2.Financeiro.App"
... a lot of NS ...
xmlns:vm="clr-namespace:TryERP2.Financeiro.ViewModel"
StartupUri="MainWindow.xaml"
mc:Ignorable="d">
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
</Application.Resources>
</Application>
That s what happen when I execute my application. The View that was on the module should be loaded into this blank space, showing its Button, but nothing happened:
http://imageshack.us/photo/my-images/818/capturarwy.png
当我试图改变这一看法并提出一个“简单观点”(而不是使用MVVERLight)时,我的工作是完美的,如下文所示: