Windows 8 WebView - xaml

I have ran into problem, that WebVie is always on top, i have LoadingGrid (black background with image on it) it haz Z.Index =5.
First thing i show Loading screen, and when WebView finishes loading i hide Loading screen and fade in WebView.
But the problem is that WebView even with Opacity set to 0 - IS VISIBLE! And on top of my loading screen - is there a workaround? Because the only way i found to make WebView invisible set to collapsed - but then my effect doesn't have any reason...
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ShowHideWebView">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.2"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="HideWebView"/>
<VisualState x:Name="ShowWebView">
<Storyboard>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="wv1" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="18*"/>
</Grid.RowDefinitions>
<!--
<Button x:Name="bBack" BorderThickness="0" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Stretch" Click="bBackClick" >
<Button.Background>
<ImageBrush ImageSource="Assets/back_button.png" Stretch="UniformToFill"/>
</Button.Background>
</Button> -->
<WebView x:Name="wv1" HorizontalAlignment="Stretch" Visibility="Collapsed" Grid.Row="1" VerticalAlignment="Stretch" LoadCompleted="wv1_LoadCompleted" Opacity="0" />
<Image HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="0" Source="Assets/back_button.png" Tapped="backClick" />
<Grid x:Name="LoadingScreen" Grid.Row="1" Visibility="Collapsed" Canvas.ZIndex="5">
<Grid.Background>
<SolidColorBrush Color="Black" Opacity="0.5"/>
</Grid.Background>
<Image Height="100" Width="100" Opacity="0.5" Source="Assets/loading.gif" Stretch="Fill">
<Image.RenderTransform>
<RotateTransform x:Name="SpinningRotateTransform" CenterX="50" CenterY="50" />
</Image.RenderTransform>
</Image>
</Grid>
</Grid>

You have to stick to Visibility property because when opacity is 0 at that time WebView would be part of visual tree and hence it will be on top of each element. While if it's collapsed it's no longer part of visual tree. I would recommend to try WebViewBrush to show fade effect. When effect is over show WebView.

Related

How to style a scrollbar to set it's colour and stop it fading out

I am working on a WinRT application and I have a problem with a scrollbar that needs to be made more noticeable on a white background, and needs to stop disappearing.
The user is meant to answer a number of questions displayed by the listview and at present can easily miss that there are more questions off the end of the screen.
So I would like to style my scrollbars accordingly.
What I find out as a newcomer to XAML is that the solutions I have found online involve a huge amount of code and it is hard to work out from that the very simple things that I want to do.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<TextBlock Text="*" FontSize="40" FontWeight="Bold" Foreground="Red"/>
<TextBlock Text=" = Required " FontSize="20"/>
</StackPanel>
<ListView Grid.Row="1"
ItemsSource="{Binding Path=Survey.SelectedSection.Questions, Mode=TwoWay}"
IsSwipeEnabled="False"
SelectionMode="None"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Background="White"
ItemTemplateSelector="{StaticResource ResourceKey=QuestionDisplay}"
ItemContainerStyle=
"{StaticResource ResourceKey=QuestionListViewItemContainerStyle}" />
</Grid>
So how do I set the colour of the scrollbars and stop them from fading out?
I found that I can get the default styles from here: https://msdn.microsoft.com/library/windows/apps/jj710190.aspx
To put my own colours in I just changed the SolidColorBrush elements. And to stop the scrollbar disappearing I commented out;
<VisualState x:Name="NoIndicator">
<Storyboard>
<FadeOutThemeAnimation BeginTime="0" TargetName="HorizontalPanningRoot" />
<FadeOutThemeAnimation BeginTime="0" TargetName="VerticalPanningRoot" />
<FadeOutThemeAnimation BeginTime="0" TargetName="HorizontalRoot" />
<FadeOutThemeAnimation BeginTime="0" TargetName="VerticalRoot" />
</Storyboard>
</VisualState>

How to correctly scale view

I'm wondering what is the best way to correcly scale a view in Windows 10 / Windows 8(.1) application.
ViewBox ?
VisualStateManager ?
Other ?
My picture are already suffixed by .scale-xxx.png
In 1366x768, I have :
And in WXGA, I have :
Here is my xaml code :
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="2*" />
<RowDefinition Height="6*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBlock Text="{x:Bind ViewModel.Player, Mode=OneWay}" Margin="20,0,0,0" VerticalAlignment="Center" />
<Image Grid.Row="0" Source="ms-appx:///Resources/Title/title-app.png" VerticalAlignment="Center" Stretch="None" HorizontalAlignment="Center" />
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right" Margin="10,5,25,5">
<Image Source="ms-appx:///Resources/Rating/star-full.png" Stretch="None" />
<TextBlock FontWeight="Bold" Margin="5,5,0,0" Text="{x:Bind ViewModel.Stars, Mode=OneWay}" FontSize="30" VerticalAlignment="Center" />
</StackPanel>
In my opinion it's the VisualStateManager because here you can find the
AdaptiveTrigger with MaxWindowWidth or MinWindowWidth. Then the diffrent VisulaStates will work perfectly.
For Example:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Width1250">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1310"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="Button1.Visibility" Value="Visible"/>
<Setter Target="Button2.Visibility" Value="Visible"/>
<Setter Target="Button3.Visibility" Value="Visible"/>
</VisualState.Setters>
</VisualState>
Hope to help you :)
As blueeyes said you can achieve this using visual states. If you don't want to change design you can simply use viewbox to fit the resolution (with stretching).

WinRT Listview Scrolling Not Working in Grid

Okay so I have a parent grid, where three other grid resides in it. Problem is I've a Listview inside the last one. In this grid the listview items scrolling doesn't work. But if I move the same listview in the middle grid the scrolling works exactly as i want. What am I missing here? How can I make this Listview Scrolling work in the last grid. Here is the code snippets. TIA
<Grid x:Name="Container" Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="HambugerMenuStateGroup">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.3">
<VisualTransition.GeneratedEasingFunction>
<CubicEase EasingMode="EaseInOut"/>
</VisualTransition.GeneratedEasingFunction>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="HamburgerCloseState"/>
<VisualState x:Name="HamburgerOpenState">
<Storyboard>
<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="LayoutRoot" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="380" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.GlobalOffsetX)" Storyboard.TargetName="LayoutRoot" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="480" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.GlobalOffsetX)" Storyboard.TargetName="HamburerPane" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ManualDataPanelStateGroup">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.3">
<VisualTransition.GeneratedEasingFunction>
<CubicEase EasingMode="EaseInOut"/>
</VisualTransition.GeneratedEasingFunction>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="ManualDataPanelCloseState"/>
<VisualState x:Name="ManualDataPanelOpenState">
<Storyboard>
<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.GlobalOffsetY)" Storyboard.TargetName="LayoutRoot" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="-380" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.GlobalOffsetX)" Storyboard.TargetName="LayoutRoot" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="-460" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.GlobalOffsetX)" Storyboard.TargetName="ManualDataPane" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="HamburerPane"
Margin="-480,0,0,0">
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Width="400" HorizontalAlignment="Left">
<TextBlock>Hello</TextBlock>
</StackPanel>
</Grid>
<Grid x:Name="LayoutRoot">
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<maps:MapControl Grid.RowSpan="3" Grid.ColumnSpan="3" x:Name="MapControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<!--<maps:MapItemsControl ItemTemplate="{StaticResource MapControlDataTemplate}" ItemsSource="{Binding}" >
</maps:MapItemsControl>-->
</maps:MapControl>
<Slider x:Name="RotationSlider" Grid.Row="0" Grid.Column="1" Maximum="360" Value="{Binding Heading, ElementName=MapControl, Mode=TwoWay}" ></Slider>
<Slider x:Name="PitchSlider" Grid.Row="1" Grid.Column="2" Orientation="Vertical" Maximum="65" Value="{Binding DesiredPitch, ElementName=MapControl, Mode=TwoWay}" ></Slider>
</Grid>
<Grid x:Name="ManualDataPane"
Margin="0,0,-480,0">
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
<ListView ItemsSource="{Binding Origins}" Height ="{Binding ElementName=ManualDataPane, Path=ActualHeight}" Width="400" HorizontalAlignment="Right">
<ListView.ItemTemplate>
<DataTemplate>
<expaControl:ExpanderControl Width="400"
ItemsSource="{Binding Intersections}"
HeaderTemplate="{StaticResource CustomHeaderTemplate}"
ItemTemplate="{StaticResource CustomItemTemplate}" IsExpanded="False" Style="{StaticResource ExpanderControlStyle}" ExpanderTemplate="{StaticResource CustomExpanderTemplate}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Grid>
This three grids are inside a parent grid. The grid.projection are just for animating the grid like the hamburger menu. No problem there.
The Row definition for the grid is Auto for the Row it is in. If a listview is put in a row with auto it will not scroll you must use either ,1,2* etc or a fixed height.
I found recently that when I put a ListView in a Container with <PlaneProjection/> the scrolling stopped working. Taking the PlaneProjection off allowed the ListView to scroll again. Is this your problem? I'm looking for a solution myself at the moment.

How to make rotation in XAML of one element by clicking on another one?

I have such code (cut only part which is needed; this code is used as a UserControl):
<Grid>
<Image x:Name="im" HorizontalAlignment="Left" Height="120" Width="120">
<Image.RenderTransform>
<RotateTransform Angle="0" CenterX="60" CenterY="60" />
</Image.RenderTransform>
</Image>
<Button x:Name="br" Content="Right" Width="55">
<Button.Triggers>
<EventTrigger RoutedEvent="MouseUp">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="im" Storyboard.TargetProperty="RenderTransform.Angle" By="90" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
I'd like to rotate image ("im") by 90 degrees by clicking the "br" button. This code doesn't work.
But if I use this code:
<Grid>
<Image x:Name="im" HorizontalAlignment="Left" Height="120" Width="120">
<Image.RenderTransform>
<RotateTransform Angle="0" CenterX="60" CenterY="60" />
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="MouseUp">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="im" Storyboard.TargetProperty="RenderTransform.Angle" By="90" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
<Button x:Name="br" Content="Right" Width="55">
</Button>
</Grid>
rotation works (image is rotating by clicking on it). What's wrong with the first one?
Did you tried the Button.Click Routed event instead of MouseUp. The reason for MouseUp not working for button is explained here: Wpf event not bubbling.
The code you provided will work on Right button click of mouse. On left button click of mouse, the Click event is swallowing up the Mouse events.
I tried the below code and it seems to work. I have used a dummy image as source.
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Image x:Name="im" HorizontalAlignment="Left" Height="120" Width="120" Source="..\Images\info.png">
<Image.RenderTransform>
<RotateTransform Angle="0" CenterX="60" CenterY="60" />
</Image.RenderTransform>
</Image>
<Button x:Name="br" Grid.Row="1" Content="Right" Width="55">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="im" Storyboard.TargetProperty="RenderTransform.Angle" By="90" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
Let me know in case you need any more information.

XAML Grid Visibility Transition?

I have a Grid that has Visibility bound to a property in my viewmodel. This all works fine -- the Grid appears/disappears correctly. My question is, how can I apply a transition so that instead of just instantly disappearing from the screen, the grid content slides into the edge of the UI? When made visible it should slide back out again.
<Grid Grid.Row="0" Grid.RowSpan="2"
Grid.Column="0"
Margin="30,30,0,30"
Visibility="{Binding IsSearchEnabled, Converter={StaticResource visibilityConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
...
So as a quick example, one way of doing this;
<Grid Grid.RowSpan="2" x:Name="TheGrid"
Margin="30,30,0,30"
Visibility="{Binding IsSearchEnabled, Converter={StaticResource visibilityConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Start the magic -->
<Grid.RenderTransform>
<TranslateTransform x:Name="SlideIn" X="750" />
</Grid.RenderTransform>
<Grid.Triggers>
<EventTrigger RoutedEvent="Grid.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="SlideIn" Storyboard.TargetProperty="X">
<SplineDoubleKeyFrame KeyTime="0:0:1.25" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="TheGrid" Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0:0:1.55" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
</Grid>
This will slide it in when it's loaded and even fade in as it goes. You might have to play with the "X" value on SlideIn to get it off the screen to your liking. You could reverse it for the other direction.
Hope this helps.