开发者

Reset TranslateZoomRotateBehavior? (WPF/Blend behavior)

I have attached a TranslateZoomRotateBehavior 开发者_如何学运维to a Grid:

<Grid>
    <!--all sorts of content-->
    <Button Content="Cancel" Click="CancelButton_Click Width="25" Height="20"/>
    <i:Interaction.Behaviors>
        <ei:TranslateZoomRotateBehavior ConstrainToParentBounds="True" SupportedGestures="Translate"/>
    </i:Interaction.Behaviors>
</Grid>

in the CancelButton_Click eventhandler I want to reset the TranslateZoomRotateBehavior to return the Grid and it's content to it's original position. Does anyone know whether this is possible?


TranslateZoomRotateBehavior is adding MatrixTransform to element it is attached to.

So modifying your example:

<Grid Name="TestGrid">
    <!--all sorts of content-->
    <Button Content="Cancel" Click="CancelButton_Click Width="25" Height="20"/>
    <i:Interaction.Behaviors>
        <ei:TranslateZoomRotateBehavior ConstrainToParentBounds="True" SupportedGestures="Translate"/>
    </i:Interaction.Behaviors>
</Grid>

Then you can reset it in code the following way:

TestGrid.RenderTransform = new MatrixTransform();


If you name the grid that you want to reset the behaviours collection on.

<Grid x:Name="grid1">

You can get a list of the behaviors in code behind with

var b = System.Windows.Interactivity.Interaction.GetBehaviors(grid1)

You're then free to work with them however you want, if you want to remove them all .Clear() if you want to reset just values but keep the TranslateZoomRotateBehavior you can access it with

TranslateZoomRotateBehavior targetBehavior = (TranslateZoomRotateBehavior)b[0];
targetBehavior.ConstrainToParentBounds = true;
targetBehavior.SupportedGestures = ....
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜