2010-04-09 6 views
0

SampleCommand가 실행될 때 Page1.xaml에서 프레임의 source 속성을 변경하려고합니다. View Model에서이를 어떻게 달성 할 수 있습니까?MVVM 및 리본 명령

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; // pageloads 때

답변

2

이런 식으로 사용하려고 했습니까? link

here

행운

릭 편안한 스레드가 :

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; 
     }} 
} 

참조로이 프로젝트를 사용하십시오