复选框无法为已选中/未选中状态应用不同的资源画笔? [英] Can't apply different resources brushes for checked/unchecked state for checkbox ?

查看:110
本文介绍了复选框无法为已选中/未选中状态应用不同的资源画笔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


解决方案

我确信有更好的方法可以做到这一点,但我最初开始使用复选框时的解决方法是的:



  • 复制现有矩形的矩形

  • 将其设置为checkedBrush(或无论你把它命名为什么)

  • 将透明度设置为零

现在创建一个名为boxChecked的新时间轴,并将隐藏矩形的透明度设置为100%,十分之一秒。然后创建一个名为boxUnchecked的文件,并在十分之一秒内将其淡化为0%。最后一部分是将这些时间线分配给已检查/​​未检查的状态,然后你就完成了。

另一种方法是通过设置各个渐变停止的动画,我真的不喜欢这样做。如果你走这条路,你的代码将最终看起来像这样:













< tr>




































< 故事板x: Key = " RecentMenu.MouseOnlyAnimation" >
< DoubleAnimationUsingKeyFrames BeginTime = " 00:00:00"
Storyboard.TargetName = " FocusHighlight"
Storyboard.TargetProperty = "(Shape.Fill)。(GradientBrush.GradientStops)[1]。(GradientStop.Offse t)" >
< SplineDoubleKeyFrame KeyTime = " 00:00:00.2000000"
= " 0.595" />
< / DoubleAnimationUsingKeyFrames >
< ColorAnimationUsingKeyFrames BeginTime = " 00:00:00"
Storyboard.TargetName = " FocusHighlight"
Storyboard.TargetProperty = "(Shape.Fill)。(GradientBrush.GradientStops)[1]。(GradientStop) .Color)" >
< SplineColorKeyFrame KeyTime = " 00:00:00.2000000"
= "#39FFFFFF" />
< / ColorAnimationUsingKeyFrames >
< ColorAnimationUsingKeyFrames BeginTime = " 00:00:00"
Storyboard.TargetName = " FocusHighlight"
Storyboard.TargetProperty = "(Shape.Fill)。(GradientBrush.GradientStops)[2]。(GradientStop) .Color)" >
< SplineColorKeyFrame KeyTime = " 00:00:00.2000000"
= "#36000000" />
< / ColorAnimationUsingKeyFrames >
< / DoubleAnimationUsingKeyFrames >
< / Storyboard >

Hi,


解决方案

I'm sure there's a better way to do this, but my workaround when I initially started working with checkboxes was to:

  • duplicate the rectangle on top of the existing one
  • set it to the checkedBrush (or whatever you've named it)
  • set the transparency to zero

Now create a new timeline called boxChecked and set the transparency of your hidden rectangle to 100% at a tenth of a second into it. Then make one called boxUnchecked and have it fade back to 0% at a tenth of a second. The last part is to assing these timelines to the checked/unchecked states, then you're all done.

The other way to do it is by animating the individual gradiant stops, which I really don't like doing. If you go this route, your code will end up looking like this:

<Storyboard x:Key="RecentMenu.MouseOnlyAnimation">  
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                       Storyboard.TargetName="FocusHighlight" 
                                       Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Offset)">  
            <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" 
                                  Value="0.595" /> 
        </DoubleAnimationUsingKeyFrames> 
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" 
                                      Storyboard.TargetName="FocusHighlight" 
                                      Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">  
            <SplineColorKeyFrame KeyTime="00:00:00.2000000" 
                                 Value="#39FFFFFF" /> 
        </ColorAnimationUsingKeyFrames> 
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" 
                                      Storyboard.TargetName="FocusHighlight" 
                                      Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">  
            <SplineColorKeyFrame KeyTime="00:00:00.2000000" 
                                 Value="#36000000" /> 
        </ColorAnimationUsingKeyFrames> 
     </DoubleAnimationUsingKeyFrames> 
</Storyboard> 
 


这篇关于复选框无法为已选中/未选中状态应用不同的资源画笔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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