Good catch. ∞ Andy Badera ∞ +1 518-641-1280 ∞ This email is: [ ] bloggable [x] ask first [ ] private ∞ Google me: http://www.google.com/search?q=andrew%20badera
On Wed, Sep 23, 2009 at 1:10 PM, chrismaduro <[email protected]> wrote: > > In the view model the setmodel method must be called after the data > objects are instantiated! > > On Sep 23, 10:53 am, chrismaduro <[email protected]> wrote: >> The problem we are having is that we cannot get binding to work in our >> prism silverlight application when using the view-model first >> approach. The view first approach work fine. We have gone over the >> official documentation and various web sites, but have still not >> resolved the issue. Below is the code for both the view-model first, >> and the view first approach. Are we missing something? >> >> View-Model first approach: >> --------------------------------------- >> Bootstrapper: >> >> 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 >> ----------------------------- >> >> Bootstrapper: >> 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; >> } >
