Extended Splash Screen - ProgressRing disappers on mobile - xaml

I have made an ExtendedSplashScreen by following the Microsoft docs. I have a logo and a ProressRing in the splash screen. It works well on desktop (Logo is in the center and ProgressRing is below it). But on my mobile, the ProgressRing disappears ( probably goes out of view ) but the logo is in the center.
Here's my XAML:
<Grid Background="#FFFFFF">
<Canvas>
<Image x:Name="extendedSplashImage" Source="/Assets/GeneraredSplash/SplashScreen.scale-100.png"/>
<ProgressRing Name="splashProgressRing" IsActive="True" Width="20" HorizontalAlignment="Center"/>
</Canvas>
</Grid>
Code:
namespace Project.Views
{
partial class ExtendedSplash : Page
{
internal Rect splashImageRect; // Rect to store splash screen image coordinates.
private SplashScreen splash; // Variable to hold the splash screen object.
internal bool dismissed = false; // Variable to track splash screen dismissal status.
internal Frame rootFrame;
public ExtendedSplash(SplashScreen splashscreen, bool loadState)
{
InitializeComponent();
Window.Current.SizeChanged += new WindowSizeChangedEventHandler(ExtendedSplash_OnResize);
splash = splashscreen;
if (splash != null)
{
// Register an event handler to be executed when the splash screen has been dismissed.
splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler);
// Retrieve the window coordinates of the splash screen image.
splashImageRect = splash.ImageLocation;
PositionImage();
// Optional: Add a progress ring to your splash screen to show users that content is loading
PositionRing();
}
// Create a Frame to act as the navigation context
rootFrame = new Frame();
}
// Position the extended splash screen image in the same location as the system splash screen image.
void PositionImage()
{
double ScaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
extendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.Left);
extendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Top);
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
extendedSplashImage.Height = splashImageRect.Height / ScaleFactor;
extendedSplashImage.Width = splashImageRect.Width / ScaleFactor;
}
else
{
extendedSplashImage.Height = splashImageRect.Height;
extendedSplashImage.Width = splashImageRect.Width;
}
}
void PositionRing()
{
double ScaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
splashProgressRing.SetValue(Canvas.LeftProperty, splashImageRect.X + (splashImageRect.Width * 0.5) - (splashProgressRing.Width * 0.5));
splashProgressRing.SetValue(Canvas.TopProperty, (splashImageRect.Y + splashImageRect.Height + splashImageRect.Height * 0.1));
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
splashProgressRing.Height = splashProgressRing.Height / ScaleFactor;
splashProgressRing.Width = splashProgressRing.Width / ScaleFactor;
}
}
//Other methods like DismissExtendedSplash(), DismissedEventHandler(), ExtendedSplash_OnResize(Object sender, WindowSizeChangedEventArgs e).....
}
}
I am not very familiar with image scaling, RawPixels, ScaleFactor etc. .
I found the code here
Also if you guys know some good tutorial for splash screen or something similar (other than Microsoft docs) that can help then please post the link to it.

You should put the ProgressRing control inside the Grid. It should always be in the center of the page, not the center of any child.
Also HorizontalAlignment="Center" won't do anything within a Canvas. You need to use Canvas.Left and Canvas.Top.

Related

if slightly tilt the ios device, sfcombobox scrolled up to top in xamarin forms

if slightly tilt the ios device, sfcombobox scrolled up to the top in xamarin.forms.it is occurring while the first time we entering to the page.
<combobox:SfComboBox DataSource="{Binding SamplePickerList, Mode=TwoWay}" HorizontalOptions="FillAndExpand" SelectedIndex="{Binding SamplePickerIndex, Mode=TwoWay}"
VerticalOptions="FillAndExpand" SelectedItem="{Binding SamplePicker,Mode=TwoWay}" />
You can resolve this issue by using SfComboBox Renderer and get the device rotation and UITableView content offset position. You can easily grab the exact offset of the table view by looking at its ContentOffset property.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBox_ScrollResetRotating-1020669557
Code Snippet:
public class CustomComboBoxRenderer : SfComboBoxRenderer
{
/// <summary>
/// Find device rotation.
/// </summary>
UIDeviceOrientation orientation;
public CustomComboBoxRenderer()
{
Foundation.NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UIDeviceOrientationDidChangeNotification"), this.DeviceRotated);
}
private async void DeviceRotated(NSNotification obj)
{
if (this.Control.Text == string.Empty && this.Control.IsSuggestionOpen)
{
//// Get the table view position.
var offset = this.Control.AutoCompleteTableView.TableView.ContentOffset;
await System.Threading.Tasks.Task.Delay(1);
//// Set the table view position while rotating.
this.Control.AutoCompleteTableView.TableView.ContentOffset = offset;
}
}
}
In this sample we are save the scroll position before the rotation using UIDeviceOrientation and then scroll to that row after the device tilt.

UWP: Content dialog width stays the same

I have tried to set the width and also min height and min width but still the dialogue wont change to full screen. tried window.bounds too but teh dialog wont expand beyond a fixed width.
public sealed partial class ContentDialog1 : ContentDialog
{
public ContentDialog1()
{
this.InitializeComponent();
this.MinWidth = Window.Current.Bounds.Width;
}
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
}
}
<ContentDialog
x:Class="PowerUp.UWP.View.ContentDialog1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PowerUp.UWP.View"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="TITLE"
PrimaryButtonText="Button1"
SecondaryButtonText="Button2"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
MinWidth ="2000">
<Grid x:Name="cd1" >
</Grid>
This is what I want
This is how content dialog is shown in my application
It is actually very simple, did a bit research and found the simplest answer, you can keep doing what you were already doing in the first place and just set the FullSizeDesired property of your ContentDialog to true.
Popup
Or you can try it with popup.
var c = Window.Current.Bounds;
var okButton=new Button{Content="Ok"};
okButton.Click += okButtonClicked; // now where you have this okButtonClicked event you can execute any code you want including, closing the popup.
var g = new Grid
{
Width = c.Width,
Height = c.Height,
Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0)),
Children =
{
new StackPanel
{
Width = 400,
Height = 200,
Background = new SolidColorBrush(Colors.White),
Children=
{
new TextBlock{Text="Title"},
new TextBlocl{Text="description"},
okButton
}
}
}
};
var p = new Popup
{
HorizontalOffset = 0,
VerticalOffset = 0,
Width = c.Width,
Height = c.Height,
Child = g
};
p.IsOpen = true; // open when ready
Notice that Child of popup is g which is a grid, you can put your content within this grid or you can use a StackPanel instead of this grid and then put your contents within that StackPanel, whatever you want to do here is your decision, putting elements in popup is exactly like putting elements in a ContentDialog.
Achieving the same with a simple Grid alongside your frame
<Grid>
<Grid Horizontallignment="Stretch" VerticalAlignment="Stretch" Visibility="Collapsed" x:Name="ContentGrid" canvas.ZIndex="5"><--this grid will act as content dialog, just toggle its visibility to the backend-->
<--put all your content here along with your ok and cancel buttons-->
</Grid>
<Frame/> <--this is the code where you have your frame-->
</Grid>
in above code the frame and your actually content grid will be parallel to each other, and whenever content grid is visible only it will be shown in the app because it has ZIndex greater than 0 and your frame will hide behind it, and whenever its visibility is collapsed it will not be shown and you will be able to see your frame normally.

UWP/c++-cx - Moving a button on the vertical axis by dragging it

I have a Grid which is as high as the application and has the width of 50. I have got a button in it on the left top with the width of 50 also. I want to move this button along the vertical left axis by dragging it with the mouse. But it should be stil able to be clicked normally. I tried to do this with the drag-and-drop sample by microsoft but the procedure I want to implement is not quite drag-and-drop. How can I implement this by using XAML and c++-cx as code behind in an universal windows app ?
My XAML-Code for the Grid/Button:
<Grid x:Name="Grid1" Width="50" >
<Button x:Name="btnMove" Content="Move me!" Background="PaleGreen" Click="btnMove_Click" VerticalAlignment="Top" HorizontalAlignment="Left" Width="50" Height="50"></Button>
</Grid>
For your requirement, you could move the button on the vertical axis by using ManipulationDelta class. And you could achieve it with the following code.
For more please refer to Handle pointer input. Here is official code sample.
MainPage::MainPage()
{
InitializeComponent();
InitManipulationTransforms();
btnMove->ManipulationDelta += ref new ManipulationDeltaEventHandler(this, &MainPage::btnMove_ManipulationDelta);
btnMove->ManipulationMode = ManipulationModes::TranslateX;
}
void App14::MainPage::InitManipulationTransforms()
{
transforms = ref new TransformGroup();
previousTransform = ref new MatrixTransform();
previousTransform->Matrix = Matrix::Identity;
deltaTransform = ref new CompositeTransform();
transforms->Children->Append(previousTransform);
transforms->Children->Append(deltaTransform);
// Set the render transform on the rect
btnMove->RenderTransform = transforms;
}
void App14::MainPage::btnMove_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
}
void MainPage::btnMove_ManipulationDelta(Platform::Object^ sender, ManipulationDeltaRoutedEventArgs^ e)
{
previousTransform->Matrix = transforms->Value;
// Get center point for rotation
Point center = previousTransform->TransformPoint(Point(e->Position.X, e->Position.Y));
deltaTransform->CenterX = center.X;
deltaTransform->CenterY = center.Y;
// Look at the Delta property of the ManipulationDeltaRoutedEventArgs to retrieve
// the rotation, scale, X, and Y changes
deltaTransform->Rotation = e->Delta.Rotation;
deltaTransform->TranslateX = e->Delta.Translation.X;
deltaTransform->TranslateY = e->Delta.Translation.Y;
}
You could change the scrolling direction of the button by modifying the ManipulationMode of button.
btnMove->ManipulationMode = ManipulationModes::TranslateY;

Xamarin Dim Page (Master Detail Page)

So for Android when the master page of a master-detail page is shown the master page is covered with a "black dim" view so it is easy to differentiate the two pages with the eye. In iOS the detail page is not dimmed so it is tougher to differentiate the views. Is there a way to overlay the details page with a BoxView or Frame that is "black translucent" so it dims the page in similar fashion to Android. I have tried many different colors and opacities of a box view but they all completely cover the screen and you can't "see through them". Any ideas? Or better solutions? Even if it is a customer renderer for the BoxView that will work. I just need color ideas/settings to make it see through.
Sample here:
https://github.com/jgold6/XamarinSupportSamples/tree/master/XForms-TestShadingiOSDetailPage
Here's the code in case the link ever breaks:
MasterDetailPage mdPage;
Color origContentBgColor;
Color origPageBgColor;
public App()
{
mdPage = new MasterDetailPage();
mdPage.IsPresentedChanged += async (object sender, EventArgs e) => {
if (Device.OS == TargetPlatform.iOS) {
if (mdPage.IsPresented) {
var currentPage = (DetailPage)((NavigationPage)mdPage.Detail).CurrentPage;
origPageBgColor = currentPage.BackgroundColor;
origContentBgColor = currentPage.Content.BackgroundColor;
currentPage.BackgroundColor = Color.Black;
currentPage.Content.FadeTo(0.5);
if (currentPage.Content.BackgroundColor == Color.Default) {
currentPage.Content.BackgroundColor = Color.White;
}
}
else {
var currentPage = (DetailPage)((NavigationPage)mdPage.Detail).CurrentPage;
currentPage.BackgroundColor = origPageBgColor;
currentPage.Content.BackgroundColor = origContentBgColor;
currentPage.Content.FadeTo(1.0);
}
}
};
mdPage.Master = new MasterPage(){Title = "Master Page"};
mdPage.Detail = new NavigationPage( new DetailPage());
// The root page of your application
MainPage = mdPage;
}
I just changed the order of FadeTo() method to be the last command and the dark black effect is gone!
await currentPage.Content.FadeTo(0.5);

How to set WebView Scroll as per dynamic content size without overlaying XAML Control in Windows Store App

I was working on a project where I have to show the Dynamic HTML content on the Web View Control. Bt because of unexpected behavior of Web View control I was not able to add the Scroll value to it. I tried same with Scroll Viewer bt it was Overlaying the other XAML Control.
Than after doing lots of google search and self logic ... I came to the final solution and would like to share with you guys.
Below is the code for my Web View
WebView x:Name="WebView6" Margin="-8,0,0,0" Grid.Row="1" Width="400"
HorizontalAlignment="Left" Loaded="WebView_OnLoaded"
LoadCompleted="WebView_OnLoadCompleted"
conv:HtmlBinder.HTML="{Binding BriefDescription}"
Below is the code of my HTML Binder in Web View's Script Notify Event
static void webView_ScriptNotify(object sender, NotifyEventArgs e)
{
try
{
if (sender != null)
{
var webView = ((WebView)sender);
double contentHeight = Convert.ToDouble(e.Value) * 1.5;
double screenHeight = Window.Current.CoreWindow.Bounds.Height - 185;
webView.Height = contentHeight > screenHeight ? screenHeight : contentHeight;
webView.UpdateLayout();
}
}
catch (Exception ex)
{
}
}