Using Xamarin for development often uses the load HUD function, which is one of our common loading actions, using Andhud under Android, and using Btprogresshud under IOS, both on NuGet. The way it is provided in the UWP itself does not fully meet our needs, so we need to use dependencies to redefine the HUD functionality of the platform, which can be done using the Popup . The popup itself is a popup control that allows you to add a variety of other controls to the control, which makes it easy for us to customize pop-up windows. First, we'll set the popup size to the size of the area that the app sees. In the middle of the popup, load a grid,grid inside to load the required text and pictures can come. The instance code is as follows:
usingBS. Dependencies;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingxamarin.forms;usingWindows.UI.Xaml.Controls;usingWindows.UI.Xaml.Controls.Primitives;usingWindows.UI.Xaml.Media;usingWindows.ui;usingWindows.UI.Xaml; [Assembly:dependency (typeof(BS. UWP. DEPENDENCIES.HUDUWP)]namespaceBS. UWP. dependencies{ Public classHuduwp:ihud {PrivateWindows.UI.Xaml.Controls.Grid Container =NewWindows.UI.Xaml.Controls.Grid () {Background=NewSolidColorBrush (colors.black), Cornerradius=NewCornerradius (Ten), Padding=NewWindows.UI.Xaml.Thickness (Ten), HorizontalAlignment=HorizontalAlignment.Center, VerticalAlignment=Verticalalignment.center,}; PrivatePopup popup =NULL; Publichuduwp () { This. Popup =NewPopup () { child=NewBorder () {Width=Window.Current.Bounds.Width, Height=Window.Current.Bounds.Height, Background=NewSolidColorBrush (Colors.gray), Opacity=0.6, HorizontalAlignment=HorizontalAlignment.Center, VerticalAlignment=Verticalalignment.center, child= This. Container,}}; } Public voidShow () { This. Show ("Hello World",60000); } Public voidShow (stringmessage) { This. Show (Message,60000); } Public voidShow (stringMessageintDelay = +) { This. Popup.isopen =true; This. Container.Children.Clear (); This. CONTAINER.CHILDREN.ADD (NewTextBlock () {Text=message, Foreground=NewSolidColorBrush (colors.white), FontSize= - }); } Public voidDismiss () { This. Popup.isopen =false; } }}
Already on the code after I test can be used, hope to develop useful for you. At the same time, the above code can be used under the win8.1 and Winphone platforms. If there is a better way, please leave a message.
Xamarin UWP Set HUD load Feature