The problem we are facing is that we cannot become attached to work in our Silverlight Prism when we first use the viewing model approach. The first review approach works fine. We switched to official documentation and various websites, but still have not resolved the issue. Below is the code for the first presentation model, and the first look approach. Are we missing something? Read about it on my blog http://silvercasts.blogspot.com
The first approach to model presentation:
Loader:
internal void RegisterLoginRegionAndView()
{
IRegionManager regionManager = Container.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion(ShellRegionNames.MainRegion,
() => Container.Resolve<IViewModel>().View);
}
ViewModel:
public ViewModel(IView view)
{
View = view;
View.SetModel(this);
User = new User();
User.Username = "TestUser";
}
ViewModel Interface:
public interface IViewModel
{
IView View { get; set; }
}
View Interface:
public interface IView
{
void SetModel(IViewModel model);
}
View Xaml:
<TextBox x:Name="Username" TextWrapping="Wrap" Text="{Binding User.Username}" />
View code behind:
public void SetModel(IViewModel viewModel)
{
this.DataContext = viewModel;
}
View first approach
Loader:
regionManager.RegisterViewWithRegion(ShellRegionNames.MainRegion, typeof(IView));
ViewModel:
public ViewModel()
{
User = new User();
User.Username = "TestUser";
}
View code behind:
public View(IViewModel viewModel)
{
InitializeComponent();
this.DataContext = viewModel;
}