相关疑难解决方法(0)

WPF - 如何在父项的鼠标悬停时更改子项的样式

我有一个StackPanel(1),另一个StackPanel(2)在里面.

应隐藏SP 2(不透明度:0),直到SP 1悬停.鼠标悬停应将SP2的样式更改为不透明度:100.

在此输入图像描述

我已经尝试在StackPanel资源中定义样式,然后在那里使用触发器然后定位内部面板,但我不确定我应该如何从触发器内部定位子项.

这样做的简单风格结构是什么?

wpf xaml

11
推荐指数
1
解决办法
9604
查看次数

用于子控件的WPF鼠标悬停触发效果

可以说我有这段代码:

<Window>
    <Window.Resources>
        <Color x:Key="MyColor"
               A="255"
               R="152"
               G="152"
               B="152" />
        <DropShadowEffect x:Key="MyEffect" 
                          ShadowDepth="0"
                          Color="{StaticResource MyColor}"
                          BlurRadius="10" />
        <Style x:Key="MyGridStyle"
               TargetType="{x:Type Grid}">
            <Setter Property="Height"
                    Value="200" />
            <Setter Property="Width"
                    Value="200" />
            <Style.Resources>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="Width"
                            Value="100" />
                </Style>
                <Style TargetType="{x:Type Image}">
                    <Setter Property="Height"
                            Value="100" />
                    <Setter Property="Width"
                            Value="100" />
                </Style>
            </Style.Resources>
            <Style.Triggers>
                <Trigger Property="IsMouseOver"
                         Value="true">
                    <!-- How do I apply my effect when this grid is hovered over to Image and TextBox, but not the grid itself? -->
                </Trigger>
            </Style.Triggers> …
Run Code Online (Sandbox Code Playgroud)

wpf triggers mouseover effect childcontrol

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

wpf ×2

childcontrol ×1

effect ×1

mouseover ×1

triggers ×1

xaml ×1