Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Silverlight + MVVM = More questions
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeremiah Morrill  
View profile  
 More options Nov 28 2008, 11:39 pm
From: "Jeremiah Morrill" <jeremiah.morr...@gmail.com>
Date: Fri, 28 Nov 2008 20:39:08 -0800
Local: Fri, Nov 28 2008 11:39 pm
Subject: 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 ontrols">
    <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>


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google