简体   繁体   English

在XAML中处理点击事件[UWP]

[英]Handling Click Events in XAML [UWP]

I've got a Panel in my project that is collapsed on the click event of a button, as well as on the Checked event of a radio button. 我的项目中有一个面板,该面板在按钮的click事件以及单选按钮的Checked事件中折叠。

Currently, I am handling this easily in the code behind. 目前,我正在后面的代码中轻松处理此问题。

private void OkButton_Click(object sender, RoutedEventArg e)
{
    myPanel.Visibility = Visibility.Collapsed;
}

private void radioButton_Checked(object sender, RoutedEventArg e)
{
    myPanel.Visibility = Visibility.Collapsed;
}

But I am told to do it now in XAML only (probably using states in STYLE or such). 但是,我被告知现在只能XAML中执行此操作(可能使用STYLE之类的状态)。
Is there a way? 有办法吗?

You should Use XamlBehaviors( https://github.com/Microsoft/XamlBehaviors/wiki/ChangePropertyAction ). 您应该使用XamlBehaviors( https://github.com/Microsoft/XamlBehaviors/wiki/ChangePropertyAction )。

 <Button x:Name="OkButton" Content="OK">
            <Interactivity:Interaction.Behaviors>
                <Interactions:EventTriggerBehavior EventName="Click" SourceObject="{Binding ElementName=OkButton}">
                    <Interactions:ChangePropertyAction TargetObject="{Binding ElementName=myPanel}" PropertyName="Visibility " Value="Collapsed"/>
                </Interactions:EventTriggerBehavior>
            </Interactivity:Interaction.Behaviors>
        </Button>

You can use the same with reference of radioButton too. 您也可以将其与radioButton的引用一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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