WPF-Triiger不起作用 [英] WPF - Triiger Doesnt Work

查看:77
本文介绍了WPF-Triiger不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有人可以告诉我此触发器为何不起作用:

   

Hi,

Somebody can tell me why this trigger doesnt work:

   

<!--Style-->
    <Style x:Key="Test" TargetType="{x:Type Expander}">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="IsExpanded" Value="false"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>

    <!-- Syle applyed in expander -->
    <Expander Header="Expander" Margin="40,89,118,0" Name="expander1" Height="23" VerticalAlignment="Top" Style={StaticResource Test} >
                <Grid>
                    <Ellipse Height="100" Margin="86,0,-8,-58" Name="ellipse1" Stroke="Black" VerticalAlignment="Bottom" />       
                </Grid>
            </Expander>


    <!-- Code Behind -->
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                this.expander1.IsEnabled = false;
            }



我尝试了其他方法,但没有成功..
禁用扩展器时,还有另一种折叠内容的方法.



I try in other ways, but without success..
Have another way to collapse content when expander is disabled.

推荐答案


参见此

Hi,
See this

  <Grid>
        <Expander IsEnabled="{Binding ElementName=CheckBox1,Path=IsChecked}" Header="Expander1" Margin="67,103,61,59" Name="Expander1">
            <Expander.Style>
                <Style TargetType="{x:Type Expander}">
                    <Style.Triggers>
                           <Trigger Property="IsEnabled" Value="True">
                            <Setter Property="IsExpanded" Value="True"/>
                        </Trigger>
                    </Style.Triggers>  
                </Style>
            </Expander.Style>  
            <Grid >
                <Label Content="Hello"/>
            </Grid>
        </Expander>
        <CheckBox Height="16" Margin="67,40,91,0" Name="CheckBox1" VerticalAlignment="Top">CheckBox</CheckBox>
    </Grid>


这是因为您编写的那个控件由于禁用到那时才被触发,因此 IsExpanded 无法设置.发生的方式与此相反,因此可以正常工作

希望对您有所帮助


Think this is because the one you had written does not trigger since the control becomes disabled by then,after which the IsExpanded is not being able to set.In this it happens the opposite way so it works

Hope it helps


这篇关于WPF-Triiger不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆