Think you're in wrong direction, you have to change rootvisual content, my
application uses a navigation system based on this blog and it works great!
In my case, I changed the logic a bit because, after login only the internal
area has to change based on navigation but approach is exactly the same
http://www.flawlesscode.com/post/2008/03/Silverlight-2-Navigating-Bet...
ml-Pages.aspx
Corrado
From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Jeremiah Morrill
Sent: sabato 29 novembre 2008 10:57
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] Re: Silverlight + MVVM = More questions
Yeah, specifically here, that's exactly what I'm trying to accomplish.
Generally, I want be able to "replace one control with another", and of
course stick close to being MVVM. The ContentControl would eventually be
replaced with something that would maybe do a transition when the content
changed.
I know some things need a little home-brew TLC in SL (ie Commanding), but I
am left wondering if I'm applying the pattern incorrectly and/or not
leveraging the SL framework. So far, to me, making controls on a lower
level makes a lot of sense, but gluing them together at a higher level is
where my understanding of how to implement MVVM in SL falls apart.
-Jer
On Fri, Nov 28, 2008 at 9:25 PM, Corrado Cavalli <corradocava...@gmail.com>
wrote:
Hi Jeremiah,
Are you trying to implement a sort of Login page then, after authentication,
do you want to 'move' to main page?
Corrado
From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Jeremiah Morrill
Sent: sabato 29 novembre 2008 05:39
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] Silverlight + MVVM = More questions
I'm still trying to grok, as they say, MVVM in Silverlight. So if any of
this sounds ignorant, don't be shy about letting me know.
So essentially I have a ViewModel such as this:
public class MainLayoutViewModel : ViewModelBase
{
private LoginViewModel m_loginController = new LoginViewModel();
private TestViewModel m_testController = new TestViewModel();
private ViewModelBase m_currentViewModel;
public MainLayoutViewModel()
{
CurrentViewModel = m_loginController;
}
public ViewModelBase CurrentViewModel
{
get { return m_currentViewModel; }
set
{
m_currentViewModel = value;
InvokePropertyChanged("CurrentViewModel");
}
}
}
Now when my LoginViewModell "authenticates", I suppose I want to change the
"CurrentViewModel" property to a new view model. In my View, I would like
to change the DataTemplate "View" to the matching ViewModel, but it seems
something like this is not supported in SL. I found some great support for
this in the SL Extensions <http://slextensions.net> (ResourceSelector), but
I was wondering how everyone else does this, or if there is a better way or
if I'm just doin' it wrong? My View with the SL extension looks like this:
<UserControl x:Class="SKMEventUI.MainLayoutView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Views="clr-namespace:MyNamespace.Views"
xmlns:Data="clr-namespace:SLExtensions.Data;assembly=SLExtensions"
xmlns:Controls="clr-namespace:SLExtensions.Controls;assembly=SLExtensions.C o
ntrols">
<UserControl.Resources>
<Data:ResourceSelector x:Key="controlTemplateSelector">
<ResourceDictionary>
<DataTemplate x:Key="LoginViewModel">
<Border BorderBrush="Black" BorderThickness="1,1,1,1">
<Views:LoginView/>
</Border>
</DataTemplate>
<DataTemplate x:Key="TestViewModel">
<Views:TestView />
</DataTemplate>
</ResourceDictionary>
</Data:ResourceSelector>
<DataTemplate x:Key="controlItemTemplate">
<ContentControl Content="{Binding}"
ContentTemplate="{Binding
Converter={StaticResource controlTemplateSelector}}" />
</DataTemplate>
</UserControl.Resources>
<StackPanel x:Name="LayoutRoot" Background="White">
<ContentControl Content="{Binding CurrentViewModel}"
ContentTemplate="{StaticResource
controlItemTemplate}" />
</StackPanel>
</UserControl>