WinRT DoubleAnimation to Canvas.Left - xaml

Quick question for the pros. I have a userControl sitting in the centre of my page. When the page is tapped I want to use a doubleAnimation to dock the control to the left of the page.
This line To="{Binding Canvas.Left}" is not working. I have to specify a value. eg. -200 which will animate (TranslateX) to the left but for some screens it never reaches the left of the page. How should I handle this? Also is the tapped event of the page the correct place to check for the first interaction on the page since it should only happen the first time the user interacts?
In my code behind I want to use something like if(usercontrol.left > 0){storyboard.begin;}. What is the best way to achieve this?
I will probably have to put a From={Binding UserControl.CurrentPosition} as well
Thanks
<Page.Resources>
<Storyboard x:Name="EntryAnimation">
<DoubleAnimation Duration="0:0:1"
To="{Binding Canvas.Left}"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)"
Storyboard.TargetName="idcMain"
d:IsOptimized="True" />
</Storyboard>
</Page.Resources>

Instead of using storyboards, You can use system transitions (RepositionTransition in your case). This way, You Just modify the Canvas.Left property and it's automagically animated using transitions timing consistent with the global OS UX.

Related

How to dynamically change position of Text and Image depending upon windows size in xaml

I want to change the position of image and Text when the user resize the app window and width is very small. Please refer the attached gif which shows it happening for a Windows Settings app. I want to do achieve something similar to this.
I want to change the position of image and Text when the user resize the app window
What you are looking for is Adaptive layouts with visual states and state triggers.
When your app window grows or shrinks beyond a certain amount, you could alter layout properties to reposition, resize, reflow, reveal or replace sections of your UI. What you need is to define different visual states for your UI first. Then apply them when the window width or window height crosses a specified threshold. The document above shows different ways to change the visual states for different windows size.
There are two common ways:
handling the Window.SizeChanged Event in the code behind. Then call the VisualStateManager.GoToState method to apply the appropriate visual state.
using the AdaptiveTrigger Class in XAML. It will be triggered to apply the visual state when the size of the window grows or shrinks beyond the value you defined.
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<!-- VisualState to be triggered when the
window width is >=640 effective pixels. -->
<AdaptiveTrigger MinWindowWidth="640" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="mySplitView.DisplayMode" Value="Inline"/>
<Setter Target="mySplitView.IsPaneOpen" Value="True"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
Please check this document for more information and code sample: Adaptive layouts with visual states and state triggers.

UWP SplitView DisplayMode Overlay - not in focus

I have a SplitView:
<SplitView Name="splitView"
DisplayMode="{Binding SplitViewDisplayMode}"
IsPaneOpen="{Binding SplitViewIsPaneOpen}"
OpenPaneLength="200" CompactPaneLength="51"/>
I am also using VisualStateManager to adjust the SplitView based on application window size: (example)
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="500"></AdaptiveTrigger>
</VisualState.StateTriggers>
Thus far everything works correctly, but I ran into an unexpected result when the trigger above and state below are activated.
<VisualState.Setters>
<Setter Value="True" Target="splitView.IsPaneOpen"></Setter>
<Setter Value="Overlay" Target="splitView.DisplayMode"></Setter>
</VisualState.Setters>
I cant seem to find a way to detect the event so that my ViewModel knows when the SplitView pane focus is lost. Right now as designed Overlay displays until the user clicks the view (as designed), but I'd like to know, when the SplitView Overlay is collapsed so that I can add additional binding events into my HamburgerMenu.
From what I am experiencing it appears that VisualStateManager doesn't update/change my bindings
DisplayMode="{Binding SplitViewDisplayMode}"
Any ideas as to how I can discover if/when the Overlay disappears/Closes?
The only thing I can think of is to create methods that discover the Window size, and then determine if the SplitView should be Inline/Compact/Overlay.. This is doable but would result in a lot of potential combinations.
Any thoughts or ideas on how to detect or get SplitView to tell me if Overlay is Collapsed when a user clicks a control outside of the SplitView?
To make the bindings work, you have to specify them as two way bindings. Without this, they will only update the UI with your changes in code, not the other way around:
<SplitView Name="splitView"
DisplayMode="{Binding SplitViewDisplayMode, Mode=TwoWay}"
IsPaneOpen="{Binding SplitViewIsPaneOpen, Mode=TwoWay}"
OpenPaneLength="200" CompactPaneLength="51"/>
Now your properties should be properly updated whenever the state changes.

Doing localization in visualstatemanager by changing x:uid?

I am adding localization to my UWP app by adding x:uid tags to all of my elements and using the multilingual toolkit. However I've run into an issue where in one case I change the text itself in the narrow view using the visualstatemanager. How can I do this in a localized app? My first thought would be to change the uid of the element to the new match the new text, I'm not sure it's possible.
Here is an example of what I'd like to do, but doesn't work:
<textblock x:Name="DescriptionTextBox" x:uid="DescriptionTextBox"/> // Normal long description
....
<VisualState x:Name="NarrowState">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="DescriptionTextBox.Uid" Value="DescriptionTextBoxShort" /> // Uid of short description
x:Uid is no dependency property on your TextBlock and can't be set at runtime. You can double check this by going to the generated code behind (.g.i.cs file) of your XAML page. To do this, hit F12 on InitializeComponent() in the constructor. Now locate your control in the generated code and start drilling down the object tree: you won't encounter a Uid property. It's a XAML directive backed up by an attribute.
How I typically solve this is having 2 TextBlocks (one collapsed) with the the long and short text and toggle Visibility between both TextBlocks in your VisualStates. Depending on what the parent container of these TextBlocks is, you might need to add a StackPanel or Grid as some parent controls can only have 1 child element.

Animating the value of a TextBlock between two values until an action completes

I was wondering whether it's possible to have an animation whereby the Text value of a TextBlock switches between two values. The FontFamily for the TextBlock is an icon font and so what I'm aiming to pull off is essentially an animated icon.
For example:
<StackPanel
x:Name="PART_LayoutRoot">
<StackPanel.Resources>
<Storyboard
x:Name="PART_Animation">
<<STRING>Animation
Storyboard.TargetName="progressBarIcon"
Storyboard.TargetProperty="Text"
From="hi" To="bye" Duration="0:0:1"
AutoReverse="True"/>
</Storyboard>
</StackPanel.Resources>
<TextBlock
x:Name="progressBarIcon"/>
</StackPanel>
Does an animation type exists that will enable me to achieve what I'm after? If not, is there any other way to do so without using a storyboard animation? I'm planning to use this animation until a certain action completes i.e. a custom busy indicator.
Any help/guidance is much appreciated.
Animating string properties is not possible this way for two reasons - there is no clear way how a string animation should look, and also the value of the Text property would be unclear/invalid during the animation.
To achieve the result you want, you will need to create two TextBlocks, one with full Opacity="1" and one with Opacity="0" and then animate these opacities - one to fade out, one to fade in - this is possible normally with the DoubleAnimation so you will not run into any issues here.

Looking for Good Thin Scrollviewer style in XAML WINRT

I have implemented semantic zoom in my page,
1) when i move screen from left to right with HAND(MY Computer is touch enabled) for reading contents off the screen,i see thin and good scrollviewer horizontally appears when i move left to right and disappears after some time, if application is kept idle.
2)When i bring my Mouse and Hover on Semantic Zoom, I see default/ larger thicker scrollbar horizantal. But i want to have one goood looking scrollviewer which eatly looks like scrollviewer mentioned in Step1 . Let me know if there are any good looking scrollviewer which thinner
It sounds like you want to make the ScrollViewer always show the thin "panning indicators" when mousing over it instead of showing the traditional ScrollBars with draggable thumbs. It's easy to do this and I'll show you an example, but please keep in mind you could be creating an accessibility problem. If a user does not have a touch-enabled device, the traditional ScrollBars with draggable thumbs allow the user to scroll. Without these, the user has to resort to keyboard or mouse wheel to scroll (assuming the user has a mouse wheel input device, or that the ScrollViewer has focusable content the user can tab into). This creates a potential accessibility problem for non-touch users.
To make sure we're referring to the same thing:
traditional mouse scrollbar
panning indicator
By default, the ScrollViewer shows the panning indicator when the user performs a touch gesture on the ScrollViewer, and shows the traditional mouse scrollbar is shown when the user moves the mouse above the ScrollViewer or clicks on the ScrollBars/Thumbs.
To make the ScrollViewer show the panning indicators for mouse input, you need to perform these steps:
Open your project in Expression Blend. Right-click your ScrollViewer and select "Edit Template > Edit a Copy...".
Dig into the ScrollViewer's template and find the vertical ScrollBar. Right-click the ScrollBar and select "Edit Template > Edit a Copy...".
Open the XAML page where the new templates were created, either in Blend or in VS. Find the ScrollBar template that you created. Inside of it, find this line: <VisualStateGroup x:Name="ScrollingIndicatorStates">.
Inside the "ScrollingIndicatorStates" VisualStateGroup, copy the code inside the "TouchIndicator" VisualState:
<Storyboard>
<FadeInThemeAnimation TargetName="HorizontalPanningRoot"/>
<FadeInThemeAnimation TargetName="VerticalPanningRoot"/>
<FadeOutThemeAnimation TargetName="HorizontalRoot"/>
<FadeOutThemeAnimation TargetName="VerticalRoot"/>
<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="HorizontalRoot">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="VerticalRoot">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
Paste this code into the body of the "MouseIndicator" visual state, overwriting what's already there.
Also, if you show a horizontal ScrollBar as well, make sure to update the horizontal ScrollBar in your modified ScrollViewer template to use the ScrollBar template you created.
So, overall pretty simple. We just had to copy the animations from the "TouchIndicator" state and paste them into the "MouseIndicator" state. Full code example is here:
https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/ScrollViewer_PanningIndicatorsOnly