This is a migrated thread and some comments may be shown as answers.

MVVM Different ViewModel for each WizardPage

3 Answers 372 Views
Wizard
This is a migrated thread and some comments may be shown as answers.
admin
Top achievements
Rank 1
admin asked on 22 Sep 2017, 08:00 AM

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.

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:ui="clr-namespace:SMS.Installer.UI"
    x:Class="SMS.Installer.UI.MainWindow"
        mc:Ignorable="d"
        Icon="Resources/favicon.ico"
        Title="SMS Installer"
        WindowStartupLocation="CenterScreen">
    <Window.DataContext>
        <ui:MainWindowViewModel/>
    </Window.DataContext>
    <Grid>
        <DockPanel>
            <telerik:RadWizard x:Name="MainWindowWizard" >

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

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

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

 

 

3 Answers, 1 is accepted

Sort by
0
admin
Top achievements
Rank 1
answered on 26 Sep 2017, 08:09 AM

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" />
 </telerik:WizardPage>

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  />
</telerik:WizardPage>

0
Accepted
Vladimir Stoyanov
Telerik team
answered on 26 Sep 2017, 04:25 PM
Hello,

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" />
 </telerik:WizardPage>

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

Regards,
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.
0
admin
Top achievements
Rank 1
answered on 26 Sep 2017, 11:57 PM
Thanks this worked
Tags
Wizard
Asked by
admin
Top achievements
Rank 1
Answers by
admin
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or