Reset TranslateZoomRotateBehavior? (WPF / Blend Behavior)

I connected the TranslateZoomRotateBehavior to the 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 event handler. I want to reset TranslateZoomRotateBehavior to return the Grid and its contents to their original position. Does anyone know if this is possible?

+4
source share
2 answers

If you name the grid in which you want to reset include a behavior collection.

 <Grid x:Name="grid1"> 

You can get a list of behaviors in code with

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

Then you can work with them as you want if you want to delete them. Clear (), if you want to reset just the values, but save TranslateZoomRotateBehavior, you can access it with

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

TranslateZoomRotateBehavior adds a MatrixTransform to the element to which it is attached.

So, changing 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 the code as follows:

 TestGrid.RenderTransform = new MatrixTransform(); 
0
source

All Articles