c# – Refer to parent Xaml element

Question:

There is the following structure

 <Grid.RenderTransform>
   <CompositeTransform />
    </Grid.RenderTransform>
  <Grid.RowDefinitions>
   <RowDefinition Height="2*" />
    <RowDefinition Height="Auto" />     
   </Grid.RowDefinitions>
     <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="Auto" />
     <ColumnDefinition Width="Auto" />
     </Grid.ColumnDefinitions>

                        <Button Width="50"
                                    Height="50"
                                    Grid.Row="0"
                                    Grid.Column="1"
                                    Margin="0,-50,0,0"
                                    ManipulationMode="Rotate"
                                    ManipulationDelta="Button_ManipulationDelta"
                                    Visibility="{Binding Value, Source={StaticResource ShowBorder}, Converter={StaticResource VisibilityInvertConverter}}" >
                            <Button.Background>
                                <ImageBrush Stretch="Fill" ImageSource="ms-appx:///Assets/Rotate.png" />
                            </Button.Background>
                            <Button.RenderTransform>
                                <CompositeTransform />
                            </Button.RenderTransform>
                        </Button>

                        <Border Width="670"
                                Grid.Row="1"
                                Grid.Column="0"
                                Grid.ColumnSpan="4"
                                ManipulationDelta="Border_ManipulationDelta"
                                ManipulationMode="TranslateX, TranslateY,Rotate,Scale">
                            <Border.RenderTransform>
                                <CompositeTransform />
                            </Border.RenderTransform>
                        </Border>

                        <Image  Grid.Row="1"
                                    Grid.Column="0"
                                    Grid.ColumnSpan="4"
                                    Margin="{x:Bind Position}"
                                    Width="650"
                                    Source="{x:Bind Image, Converter= {StaticResource UriToImageConverter}}"
                                    RenderTransformOrigin="0.5,0.5">
                            <interactivity:Interaction.Behaviors>
                                <core:EventTriggerBehavior EventName="Tapped">
                                    <core:ChangePropertyAction PropertyName="Value"
                                               TargetObject="{StaticResource ShowBorder}"
                                               Value="{Binding Value ,Source={StaticResource ShowBorder}, Converter={StaticResource VisibilityInvertConverter}}" />
                                </core:EventTriggerBehavior>
                            </interactivity:Interaction.Behaviors>
                            <Image.RenderTransform>
                                <CompositeTransform />
                            </Image.RenderTransform>
                        </Image>
                    </Grid>

Смысл в том, чтобы когда тянешь за Border изменял размер его родительский Grid

Не могу к нему обратиться из кода

Пробовал так

var container = sender as Border;
container = (FrameworkElement)VisualTreeHelper.GetParent(container);

var ct = (CompositeTransform)(container as Grid).RenderTransform;// получаю Null Reference
//Или так
var ct = (CompositeTransform)container.RenderTransform;// получаю Не может преобразовать MatrixTransform to RenderTransform

Answer:

I made it so that it was necessary to drag the Grid, but only when the cursor is on the border. For this I used the Poiner_Entered and _Exited . It turns out that we are dragging the Grid, but due to the fact that it is in the same place as the Border, it visually seems that we are dragging the Border all the same. The only caveat is that the picture flickers

To determine what Border is seen used:

 var grid = sender as Grid;
 var child = (FrameworkElement)VisualTreeHelper.GetChild(grid,3);

3 is the index of the control from top to bottom, as in the mark

Scroll to Top