简体   繁体   中英

How to close the window by Cancel button from xaml file?

I would like to close the window/dialog in xaml file. Actual xaml: ...

<Button Name="CancelButton" Content="Cancel" Controls1:ButtonUtils.DialogResult="False" />

There is no function implementing this button, like:

<Button Name="CancelButton" Content="Cancel" Controls1:ButtonUtils.DialogResult="False" Click="CancelButton_Click" />

private void CancelButton_Click(object sender, RoutedEventArgs e)
{
    Close();
}

Now CANCEL button is doing exactly the same as OK button (save content and close the window). I would like to change behaviour of CANCEL button-just to close the window. There is no implementation for CANCEL button except xaml file. XAML with OK and CANCEL buttons: ...

<Controls:WindowFooter>
    <Button Content="Ok" Name="OkButton" IsDefault="true" Controls1:ButtonUtils.DialogResult="True" >
        <Button.IsEnabled>
            <MultiBinding>
                <MultiBinding.Converter>
                    <Converters:ErrorMultiConverter/>
                </MultiBinding.Converter>
                <Binding ElementName="test1" Path="(Validation.HasError)"/>
                <Binding ElementName="test2" Path="(Validation.HasError)"/>
                <Binding ElementName="test3" Path="(Validation.HasError)"/>
                <Binding ElementName="test4" Path="(Validation.HasError)"/>
            </MultiBinding>
        </Button.IsEnabled>
    </Button>
    <Button Name="CancelButton" Content="Cancel" Controls1:ButtonUtils.DialogResult="False" />
</Controls:WindowFooter>

I`m expecting something like:

<Button Name="CancelButton" Content="Cancel" Controls1:ButtonUtils.DialogResult="False"       [Method=CloseWindow()]      />

也许Button.IsCancel属性可以帮助您?

<Button Name="CancelButton" Content="Cancel" Controls1:ButtonUtils.DialogResult="False" IsCancel=True"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM