2010-04-09 7 views
0

J'essaie de modifier la propriété source du cadre dans Page1.xaml lorsque la SampleCommand est exécutée. Comment puis-je l'obtenir dans le modèle View?Commande MVVM et ruban

Page1.xaml:


  <r:RibbonTab.Groups> 
       <r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}"> 
        <r:RibbonGroup.Command> 
         <r:RibbonCommand LabelTitle="RibbonButton"/> 
        </r:RibbonGroup.Command> 
        <r:RibbonButton x:Name="RibbonButton1" Command="{Binding Path=SampleCommand}"/> 
       </r:RibbonGroup> 
      </r:RibbonTab.Groups> 
     </r:RibbonTab> 


    </r:Ribbon> 

    <Border Name="PageBorder" Grid.Row="0" Grid.Column="1"> 
     <Frame Name="pageFrame" Source="FirstPage.xaml" /> 

    </Border> 
</DockPanel> 

C# Page1ViewModel.cs:

RelayCommand _sampleCommand;

public ICommand SampleCommand 
    { 
     get 
     { 
      // create command ?? 

      return _sampleCommand 
    } 

page1.xaml.cs:

Page1ViewModel pageViewModel;

this.DataContext = pageViewModel; // quand pageloads

Répondre

2

Avez-vous essayé d'utiliser de cette façon?

public class ViewModel{ 

private SimpleCommand divertCommand; 


public ViewModel() 
{ 
testCommand = new SimpleCommand 
     { 
      CanExecuteDelegate = x => true, 
      ExecuteDelegate = x => ExecuteCommand() 
     }; 
} 

     public SimpleCommand DivertCommand 
     { 
      get { return divertCommand; } 
     } 

     private void ExecuteCommand() 
     { 
      DivertCommand.CommandSucceeded = false; 

//Your code to execute 

      DivertCommand.CommandSucceeded = true; 
     }} 
} 

s'il vous plaît utiliser ce projet comme référence: link

il y a un joli fil here

Bonne chance

Ric