MVVM Different ViewModel for each WizardPage

4 posts, 1 answers
  1. admin
    admin avatar
    5 posts
    Member since:
    Sep 2017

    Posted 22 Sep 2017 Link to this post

    I am creating a ViewModel for a Window with a kendo Wizzard control on it. The ViewModel is getting very big because I 5 pages in my wizzard. Is there a way to bind a ViewModel to a page. 

    Sorry I am new to WPF and MVVM.

    Basically I have something like this.

            Title="SMS Installer"
                <telerik:RadWizard x:Name="MainWindowWizard" >

                    <!-- Introduction form -->
                    <telerik:WelcomeWizardPage Name="IntroductionPage" SideHeaderWidth="120">
                        <!-- some page controls removed -->
                    <!-- License agreement -->
                    <telerik:WizardPage Name="LicenseAgreementPage" SideHeaderWidth="120" AllowNext="{Binding CanLicenseAgreementPageNext}">

                       <!-- !!!!!! WANT TO PUT BINDING HERE !!!!!! -->

                       <!-- some page controls removed-->
                    <!-- License key -->
                    <telerik:WizardPage Name="LicenseKeyPage" SideHeaderWidth="120"  AllowNext="{Binding CanLicenseKeyPageNext}">
                        <!-- some page controls removed-->
                    <!-- database -->
                    <telerik:WizardPage Name="DatabasePage" SideHeaderWidth="120"  AllowNext="{Binding CanDatabasePageNext}">
                        <!-- some page controls removed-->
                    <!-- installation -->
                    <telerik:CompletionWizardPage Name="InstallationPage" SideHeaderWidth="120" AllowHelp="False">
                        <!-- some page controls removed-->



  2. admin
    admin avatar
    5 posts
    Member since:
    Sep 2017

    Posted 26 Sep 2017 in reply to admin Link to this post

    I have been trying to use binding via the element name, and using relative binding but still keep getting an error 

    In this example LicenseKeyView has a DataContext set to a MVVM model with CanPageNext property.

    <telerik:WizardPage Name="LicenseKeyPage" SideHeaderWidth="120" AllowNext="{Binding  DataContext.CanPageNext, ElementName=LicenseKeyView}" >
                        <ui:LicenseKeyView x:Name="LicenseKeyView" />

    Gives this error

    System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=LicenseKeyView'. BindingExpression:Path=DataContext.CanPageNext; DataItem=null; target element is 'WizardPage' (Name='LicenseKeyPage'); target property is 'AllowNext' (type 'Boolean')


    This is the relative binding I have tried.

    <telerik:WizardPage Name="LicenseKeyPage" SideHeaderWidth="120" AllowNext="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.CanPageNext}" >
                        <ui:LicenseKeyView  />

  3. Answer
    Vladimir Stoyanov
    Vladimir Stoyanov avatar
    113 posts

    Posted 26 Sep 2017 Link to this post


    Can you try setting you binding like this: 

    <telerik:WizardPage Name="LicenseKeyPage" SideHeaderWidth="120" AllowNext="{Binding  DataContext.CanPageNext, Source={x:Reference LicenseKeyView}}" >
                        <ui:LicenseKeyView x:Name="LicenseKeyView" />

    Let me know if that solves the problem and if I can be of any further assistance.

    Vladimir Stoyanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  4. admin
    admin avatar
    5 posts
    Member since:
    Sep 2017

    Posted 26 Sep 2017 in reply to Vladimir Stoyanov Link to this post

    Thanks this worked
Back to Top