UWP start application fullscreen and don't show minimize and close button - c#

How can you remove the titlebar and buttons in a UWP application? And always start in fullscreen. In WPF this is easy but can't find how to remove the buttons in UWP.

Tre below code in App.Xaml.cs (may be in onlaunched)
To remove the title bar.
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
Window.Current.SetTitleBar(null);
To make it full screen (which also removes buttons)
ApplicationView view = ApplicationView.GetForCurrentView();
view.TryEnterFullScreenMode();
Need to import
using Windows.ApplicationModel.Core;
using Windows.UI.ViewManagement;

Related

Customised dialog box with Xamarin Forms

I need to be able to make this kind of dialog box to be displayed when a button is pressed. I am using Acr.UserDialogs for simple dialog boxes but I don't think there is any way to get such a dialog using this library.
Any ideas on how I can do this in Xamarin Forms?
You can use the Popup plugin to display a page modally
You can create your own layout and use this awesome plugin to display your layout as popup
https://github.com/rotorgames/Rg.Plugins.Popup
How To Use --snippet from the link
Open new PopupPage
Task PushAsync(PopupPage page, bool animate = true) // Navigation.PushPopupAsync
Hide last PopupPage
Task PopAsync(bool animate = true) // Navigation.PopPopupAsync

In C# WPF window, adding button for topmost beside standard window buttons

I'd like add a button for changing window state to topmost to the built-in window buttons such as maximize, minimize, and close [please refer to this pic.]
However, I'm having hard time finding the way out as WPF seems not to provide such an API. I even thought using the icon next to the window title functioning as the button for topmost, but looks not feasible.
Is there anyway like using .dll or could I inherit the window class and add the button and corresponding event handler anyhow?
Thanks.
It will be very difficult as you can see below link:
How to add an extra button to the window's title bar?
To make things easy, you should consider implementing a custom window for that. This window will have custom buttons including Close,Minimize,Maximize along with any other buttons as well.

How to hide/remove all dialogue buttons from dialog window

I'm using ModernUI for WPF (MUI) available on codeplex. It's a nice framework and I have no issues using it as a container for my pages.
I have added a Custom Dialog window but I do not want to use any of the default buttons.
In the init method I have commented out this line:
this.Buttons = new Button[] { this.OkButton, this.CancelButton };
But, a Close button appears instead?
Any ideas?
Thanks

Disabling or removing the close button from uwp app

Universal app does not allow to remove or disable the close button it seems. We can hide it by going full screen. But when moving cursor over it, brings title bar back. Is there any way to remove the close button?
Reason : I am working on screen time. After allowed time gets over, I want to block the screen. I should remove close button so that user cant get over my app.
Edit : Removing close button wont help completely. It is a part of work. I am just asking how to remove it.
In Windows 10 version 1703 (build 10.0.15063) and beyond, you can prevent the app from closing, using the SystemNavigationManagerPreview class.
Add this to your app manifest:
<Capabilities>
<rescap:Capability Name="confirmAppClose" />
</Capabilities
You need to have the rescap namespace at the Package element:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
In the constructor of your main form, add:
var sysNavMgr = SystemNavigationManagerPreview.GetForCurrentView();
sysNavMgr.CloseRequested += OnCloseRequested;
OnCloseRequested can be implemented as follows:
private void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
{
var deferral = e.GetDeferral();
e.Handled = true;
deferral.Complete();
}
With current released API, we are able to customize the color of these three buttons in title bar. But there is no property or method could be used to disable or remove these buttons.
In UWP, we can use ApplicationView.TitleBar | titleBar property to get the title bar like following:
ApplicationViewTitleBar titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;
This property's type is ApplicationViewTitleBar. It only has several properties that can customize the button's color like:
titleBar.ButtonBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonHoverBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonHoverForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonPressedBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonPressedForegroundColor = Windows.UI.Colors.White;
Using these properties may make the close button invisible like:
However this won't actually hide these buttons. Users can still minimize or maximize the app and when the pointer is over the top right corner, they will still see the close button.
From Windows 8.1, if we want users to use only an application and do nothing else including closing the application, we can use Kiosk Mode. For more info, please see Enable Kiosk Mode in Windows 8.1 and Set up a kiosk on Windows 10 Pro, Enterprise, or Education. However this won't meet your requirement as you want to block the screen after allowed time gets over.
So UWP may not be the best choice for your requirement. You may try to implement it with classic desktop apps.
in App.Xaml.cs add this code :
// Collapse Title bar
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
Window.Current.SetTitleBar(null);
ApplicationView view = ApplicationView.GetForCurrentView();
view.TryEnterFullScreenMode();
C++ Version
// COLLAPSE THE TITLE BAR
Windows::ApplicationModel::Core::CoreApplication::GetCurrentView()->TitleBar->ExtendViewIntoTitleBar = true;
Window::Current->SetTitleBar(nullptr);
Windows::UI::ViewManagement::ApplicationView^ view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
view->TryEnterFullScreenMode();

Windows Phone navigation buttons overlap with screen resolution

below you'll see a screen running in Windows Phone 8.1 one 2 devices. Both are claiming to have Viewport Width and Height of 800x480 however as you can see from the image the 635's nav buttons are overlapping the game area.
I have checked various properties in GraphicsDevice.Adapter and GraphicsDevice.Viewport, but they are both the same!
The screen is running within C# UWP Monogame code. I set the PrefferedBackBufferWidth and Height to 480x800.
How can you tell if the nav buttons with take up part of the screen?
I will expand the answer further.
In windows phone 8.1, you have two ApplicationViewBoundsMode enum values.
UseVisible, pages inside application will use only the visible area excluding StatusBar, application bar and Soft navigation buttons.
To make your app use ApplicationViewBoundsMode.UseVisible option, add the following in app.xaml.cs before `Windows.Current.Activate();
#if WINDOWS_PHONE_APP
ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);
#endif
UseCoreWindow, lay out the window's content within the region occupied by the core window (that is, including any occluded areas- including soft navigation buttons).
To make your app use ApplicationViewBoundsMode.UseCoreWindow option, add the following in app.xaml.cs before Windows.Current.Activate();
#if WINDOWS_PHONE_APP
ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
#endif
In some cases, developers may want to use UserCoreWindow option to show content under app bar but as a side effect navigation soft buttons will occlude parts of your page to resolve it, follow the next solution.
You can listen for ApplicationView.GetForCurrentView().VisibleBoundsChanged in WindowsPhone and update the margin of your page.
Here is an article written by Joost van on fixing this issue (and a behavior that you can use out of the box)
Quoting the issue explanation from the above link
If the application view bound mode is set to ApplicationViewBoundsMode.UseCoreWindow in App.Xaml.cs the phone reports the whole screen size – not only the part that is normally taken by the status bar on top and the application bar at the bottom, but also the part that is used by the button bar.
And a snippet from his solution where he updates the margin of page
void KeepInViewBehaviorVisibleBoundsChanged(ApplicationView sender, object args)
{
UpdateBottomMargin();
}
private void UpdateBottomMargin()
{
if (WindowHeight > 0.01)
{
var currentMargins = AssociatedObject.Margin;
var newMargin = new Thickness(
currentMargins.Left, currentMargins.Top, currentMargins.Right,
originalBottomMargin +
(WindowHeight - ApplicationView.GetForCurrentView().VisibleBounds.Bottom));
AssociatedObject.Margin = newMargin;
}
}
to hide the navigation bar in your monogame windows phone 8.1 game add the following code in your app.xaml.cs file under InitializePhoneApplication() method
RootFrame = new PhoneApplicationFrame();
//I have set it to RootVisual to hide navigationbar
RootFrame.FullScreen = true;
if (RootVisual != RootFrame)
RootVisual = RootFrame;

Categories

Resources