2016-02-15 2 views
1

J'utilise le package d'outils WPF pour la classe d'assistant. D'une page Je voudrais passer à une autre page basée sur la sélection du bouton radio (Si vous cliquez sur Oui, passez de la page 3 à la page 4, sinon, cliquez sur Pas d'option, passez de Page3 à Page5) J'ai vu qu'il n'y a pas d'événement OnNext, mais il y a une propriété appelée NextPage. Je essayé faire:Evénement OnNext pour l'assistant sur le package de la boîte à outils WPF

On .xaml: 
<xctk:WizardPage.NextPage> 
      <MultiBinding Converter="{StaticResource NextPageSelectionFromPage3}"> 
       <Binding ElementName="yesForBAM" Path="IsChecked" Mode="OneWay"/> 
       <Binding ElementName="noForBAM" Path="IsChecked" Mode="OneWay"/> 
      </MultiBinding> 
     </xctk:WizardPage.NextPage> 

On .xaml.cs: 
public class NextPageSelectionFromPage3 : IMultiValueConverter 
{ 
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     if (values[0] is bool && values[1] is bool) 
      if ((bool)values[0]) 
       return "Page4"; 
     return "Page5"; 

    } 

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

Toute idée comment mettre en œuvre l'événement OnNext de dépendance?

Merci!

+0

espoir que ma réponse a aidé. Je voulais ajouter qu'il est préférable de gérer la logique de NextPage/PreviousPage dans ViewModel, lorsque vos RadioButons sont liés à la propriété VM, et VM à son tour exposer la propriété Enum pour la page, qui est convertie en WizardPage avec convertisseur. Dans ce cas, les tests unitaires seraient beaucoup plus efficaces. –

Répondre

1

Un problème avec votre convertisseur est que vous retournez la chaîne, tandis que la propriété NextPage est de type WizardPage. Mais vous pouvez le faire avec des déclencheurs en pur XAML, sans besoin de convertisseurs:

 <xctk:WizardPage> 
      <xctk:WizardPage.Style> 
       <Style TargetType="{x:Type xctk:WizardPage}"> 
        <Style.Triggers> 
         <DataTrigger Binding="{Binding IsChecked, ElementName=yesForBAM}" Value="True"> 
          <Setter Property="NextPage" Value="{Binding ElementName=page4}" /> 
         </DataTrigger> 
         <DataTrigger Binding="{Binding IsChecked, ElementName=noForBAM}" Value="True"> 
          <Setter Property="NextPage" Value="{Binding ElementName=page5}" /> 
         </DataTrigger> 
        </Style.Triggers> 
       </Style> 
      </xctk:WizardPage.Style> 


      <StackPanel Orientation="Vertical"> 
       <TextBlock Text="3" /> 
       <RadioButton Name="yesForBAM" Content="Show 4 page" IsChecked="True"/> 
       <RadioButton Name="noForBAM" Content="Do not show 4 page"/> 
      </StackPanel> 
     </xctk:WizardPage> 

     <xctk:WizardPage Name="page4"> 
      <TextBlock Text="4" /> 

     </xctk:WizardPage> 

     <xctk:WizardPage Name="page5"> 
      <TextBlock Text="5" /> 
     </xctk:WizardPage> 

Ou avec convertisseur. L'idée principale est toujours que vous devriez retourner WizardPage, pas de chaîne.

C#

public class NextPageSelectionFromPage3 : IMultiValueConverter 
{ 
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     if (values[0] is bool && values[1] is bool) 
      if ((bool)values[0]) 
       return values[2]; 

     return values[3]; 
    } 

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

XAML

  <xctk:WizardPage.NextPage> 
       <MultiBinding Converter="{StaticResource NextPageSelectionFromPage3}"> 
        <Binding ElementName="yesForBAM" Path="IsChecked" Mode="OneWay"/> 
        <Binding ElementName="noForBAM" Path="IsChecked" Mode="OneWay"/> 
        <Binding ElementName="page4" Mode="OneWay"/> 
        <Binding ElementName="page5" Mode="OneWay"/> 
       </MultiBinding> 
      </xctk:WizardPage.NextPage>