开发者

WPF - Animating object lower/higher in visual tree

I have following problem. I created Style for ContentControl that enables moving/dragging of specific item. This is created with help of MoveControl (: Control) that controls mouse down/move/up events. In this class DependencyProperty IsDragging property is defined, that i want to use to fade in/out item when it changes state.

Xaml file for my syle looks something like this.

<Style x:Key="ItemStyle" TargetType="ContentControl">
   <!-- ... -->
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ContentControl" x:Name="ctrl">
                <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=.}">

                    <s:MoveControl Cursor="SizeAll" Template="{StaticResource MoveThumbTemplate}" x:Name="moveThumb"/>

                </Grid>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    <!-- 开发者_高级运维... -->
    </Setter>
</Style>

So, i want to create animation that will be done on the ContentControl styled with ItemStyle when MoveControl.IsDragging will be set to true/false.

Thank you for help.


I figured out. The solution was to use SourceName property and link it to object of which dependency property is used. The problem was that by default 'this' object references element's DataContext value. If you set SourceName property to a non-null value, then the data binding operation will treat that value as the place where data is pushed to and pulled from

                    <ControlTemplate.Triggers>
                    <Trigger SourceName="moveThumb" Property="IsDragging" Value="true" >
                        <Trigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" 
                         From="1.0" To="0.3" Duration="0:0:0.2"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.EnterActions>
                    </Trigger>

                </ControlTemplate.Triggers>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜