Transfer to estimated / absolute position

I have a grid that covers the entire screen, and I translate it to the top of the screen (or vice versa) using the storyboard. Now I want to do the same, but at a distance of 48 pixels from above. To do this, I calculate the top position in SlideToPosition with SlideToPosition = -GridContent.ActualHeight + 48; . This is normal when the screen size is static.

The problem is that there are many situations where I have to recount this position:

  • resize application
  • orientation changes
  • mobile OSD is displayed

The result is also unstable when resized, and sometimes just wrong. I also tried using ApplicationView.GetForCurrentView().VisibleBounds.Top , but this is the same with another variable. Is there a better way to translate to this position without digesting the variable all the time?

enter image description here

 <Grid Name="GridContent"> <Grid Name="GridTranslate"> <Grid.RenderTransform> <TranslateTransform x:Name="TranslateTransformContent" /> </Grid.RenderTransform> </Grid> </Grid> <Storyboard x:Name="StoryboardUp"> <DoubleAnimation Storyboard.TargetName="TranslateTransformContent" Storyboard.TargetProperty="Y" To="{x:Bind Path=SlideToPosition, Mode=OneWay}" Duration="0:0:0.4"> </Storyboard> <Storyboard x:Name="StoryboardDown"> <DoubleAnimation Storyboard.TargetName="TranslateTransformContent" Storyboard.TargetProperty="Y" To="0" Duration="0:0:0.4"> </Storyboard> 
+5
source share
1 answer

Your approach seems a little from here, because you basically compensate your grid to a negative location, rather than resizing it.

If you insist on this approach, I suggest the following:

Measure the height of the application window when it is in “good condition” (for example, 1280x720). Translate the grid height (48 pixels) by a percentage (48/720 = 0.0666). Now every time you want to calculate the top position, do: SlideToPosition = AppWindowHeight * 0.666.

0
source

Source: https://habr.com/ru/post/1259905/


All Articles