简体   繁体   English

调试触发器(或者为什么这个触发器不起作用?)

[英]Debugging Triggers (or why doesn't this trigger work?)

I am trying to fade in a control when it becomes visible. 当它变得可见时,我试图淡入控件。 The following compiles and runs fine, it just doesn't fade in (control instantly appears when IsActive is set to true) 以下编译并运行正常,它不会淡入(当IsActive设置为true时控件立即出现)

<UserControl x:Class="blah"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:util="clr-namespace:blah.Util"
             mc:Ignorable="d" 
             d:DesignHeight="250" d:DesignWidth="400">
    <UserControl.Resources>
        <util:BooleanToVisibilityConverter x:Key="BoolToVis" />

        <Style TargetType="UserControl">
            <Style.Triggers>
                <Trigger Property="Visibility" Value="Visible">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:1.25" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <UserControl.Visibility>
        <Binding Path="IsActive" Converter="{StaticResource ResourceKey=BoolToVis}" ConverterParameter="False" />
    </UserControl.Visibility> 

    <!-- Snip rest of simple control -->

</UserControl>

Firstly, I'd be grateful if anyone could tell me why this isn't working. 首先,如果有人能告诉我为什么这不起作用,我将不胜感激。

Secondly I was wondering if there is any way to debug such things, as I often find myself trying to get triggers working properly. 其次,我想知道是否有任何方法来调试这些事情,因为我经常发现自己试图使触发器正常工作。 Currently my debugging consists of staring at the XAML to try and see what's wrong, or randomly changing bits to try and narrow down the area. 目前我的调试包括盯着XAML尝试查看错误,或随机更改位以尝试缩小区域。

What I really want to do it put a breakpoint on the <Trigger Property="Visibility" Value="Visible"> bit, to see if that is being triggered as a starting point. 我真正想要做的是在<Trigger Property="Visibility" Value="Visible">位上设置断点,以查看是否将其作为起点触发。 Obviously I can't do this but was wondering if there's any way to do more structured debugging rather than my current random poking at a blank wall. 显然我不能这样做但是想知道是否有任何方法可以进行更多结构化调试而不是我当前在空白墙上随机戳。 :-/ : - /

在Style中设置UserControl.Visibility ,或者如果明确设置Visibility属性,则将覆盖Style.Trigger

<Setter Property="Visibility" Value="{Binding Path=IsActive, Converter={StaticResource ResourceKey=BoolToVis}, ConverterParameter=False}" />

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

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