开发者

MVVM and Ribbon Command

I am trying to change the source property of the frame in Page1.xaml when the SampleCommand is excecuted. How do I acheive this in the View Model?

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


Have you tried to use is this way?

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

please use this project as a reference: link

there is a nice thread here

Good luck

Ric

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜