簡體   English   中英

單擊按鈕時調用兩個命令-ViewModel中的一個在后面的代碼中

[英]Call two commands on a button click - one in ViewModel one in code behind

按鈕控制:

<Button Content="OK" Grid.Row="2" IsDefault="True" Style="{StaticResource ButtonFormStyle}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <i:InvokeCommandAction Command="{Binding RequestConfigurationCommand}" />
                    <!--<i:InvokeCommandAction Command="{Binding ValidateCommand} />  doesn't work --> 
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>

ViewModel-視圖的DataContext:

RequestConfigurationCommand = new RelayCommand(ExecuteRequest);
private void ExecuteRequest()
{
    Validate();

    DoStuff();
}

xaml.cs:

private void ValidateCommand()
{
    // Do some stuff
}

那么,我該怎么做呢? 這可能嗎?

您可以使用按鈕點擊事件,在這種情況下,首先點擊事件將觸發,然后命令將觸發,因此

<Button Content="OK" Grid.Row="2" IsDefault="True" Style="{StaticResource ButtonFormStyle}"
        Click="btn_click">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM