简体   繁体   English

单击椭圆时更改不透明度? - WPF

[英]Change opacity when ellipse is clicked? - WPF

I want to change the opacity of my ellipse when it's clicked.我想在单击时更改椭圆的不透明度。 So if you click the ellipse, it goes from an opacity of 1 to 0.2, and if you click it again, it switches back.因此,如果您单击椭圆,它的不透明度会从 1 变为 0.2,如果再次单击它,它会切换回来。

Currently, my ellipse is using a complex multibinding目前,我的椭圆正在使用复杂的多重绑定

                            <Ellipse.Fill>
                                <MultiBinding Converter="{StaticResource FloatToCorConv}">
                                    <Binding Path="FValue" Mode="OneWay" />
                                    <Binding Path="MValue" Mode="OneWay" />
                                    <Binding Path="GId" Mode="OneWay" />
                                    <Binding Source="{x:Static foo:Bar.Instance}" Path="IsLiked" Mode="OneWay" />
                                </MultiBinding>
                            </Ellipse.Fill>

I have a boolean called IsRemoved that is a property like FValue , but I'm not sure how I can link this to a mouse click for the opacity to change.我有一个名为IsRemoved的 boolean ,它是一个类似FValue的属性,但我不确定如何将其链接到鼠标单击以更改不透明度。 I have some other button interactions for my ellipse so far.到目前为止,我的椭圆还有一些其他按钮交互。

                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseEnter">
                                <utils:InteractiveCommand Command="{Binding RelativeSource=
                    {RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.MouseEnter}"/>
                            </i:EventTrigger>
                            <i:EventTrigger EventName="MouseLeave">
                                <utils:InteractiveCommand Command="{Binding RelativeSource=
                    {RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.MouseLeave}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>

This display can be created using a ToggleButton with an appropriate Style / ContentTemplate可以使用具有适当Style /内容ContentTemplateToggleButton创建此显示

<ToggleButton>
    <ToggleButton.Style>
        <Style TargetType="{x:Type ToggleButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Ellipse
                            x:Name="TheEllipse"
                            Width="64"
                            Height="32"
                            Fill="#0000FF"
                            Stroke="Black"
                            StrokeThickness="2" />

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="TheEllipse" Property="Fill" Value="#550000FF" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ToggleButton.Style>
</ToggleButton>

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

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