Creating a full-screen option from WPF tab controls - c#

I have inherited a comprehensive WPF (C#) application that makes extensive use of tabs and other WPF controls. How do I go about creating a full-screen option for some of these tabs? I have used WPF extensively before but I'm trying to maximize the amount of code re-use for this part of my application.
This application is often show using a notebook connected to a projector on a 6'x6' screen. So any help with optimizing the WPF controls for this type of set-up would be appreciated.

Open it in a new window with WindowStyle set to None and ResizeMode set to NoResize this will make it full screen... You could use a DataTemplate for your tab header that will display full screen button and another button on the full screen window to close it and return to the app...

Does the full-screen window need to be interactive? If you just want to display the content there, you could paint the background with a VisualBrush. On a full-screen window, define the background as:
<Window.Background>
<VisualBrush Visual="{Binding Path=SelectedContent}" />
</Window.Background>
Set the DataContext of this window to your TabControl, and the selected tab content will be copied to it and stretched to the full window size.

Related

NavigationView Compact and Overlay

I`m exploring the navigationview control for uwp projects. I noticed that when I resize the window to a smaller size the menu changes to compact mode and, if the the window is small enough it overlays over the right page window rather than pushing it to the side.
I want to change the navigationview control to have this behavior by default without having to resize the window to a smaller size. The goal is to have the page window with the most space available possible.
I tried some properties but none worked, any pointers how to change this default behavior(Overlay and always in compact mode)?
you should use the latest NavigationView by winui library, and in this control you have a property PaneDisplayMode, explore values of this property and you can know what exactly you want. In your scenario you want the left pane to completely disappear and overlay then you can try LeftMinimal but if you want it in compact mode which shows only Icons then you can use LeftCompact
You can try to confugure the CompactModeThresholdWidth and ExpandedModeThresholdWidth properties of NavigationView. These properties will get or set the minimum window width at which the NavigationView enters Compact or Expanded display mode.
<NavigationView CompactModeThresholdWidth="280" ExpandedModeThresholdWidth="2800"/>
You can set the width value base on your requirement. For example, if you want the NavigationView alway in Compact Mode, you can use above code with any CompactModeThresholdWidth property value smaller than the minimum default UWP app window width and the ExpandedModeThresholdWidth property value larger than the maximum window width.

UWP XAML NavigationMenu Change behavior

I'm using NavigationView in a UWP project that contains a Frame to load pages.
When the windows is small enough the NavigationView Pane is automatically closed only showing the Icons of the MenuItems, if the Menu is specifically opened (clicking the top button) the menu overlaps the pages inside the frame (this happens after a given threshold, when the Window becomes smaller)
I was trying to maintain this behavior all the time (instead of only when the window is resized to small values), even if the window is maximized or is resized to large values.
isPaneOpen appears to be a read only property that does not work at Run time.
The overlap (rather than pushing the frame to the right) I don't know how to get this NavigationView display all the time...
Any help how to do this?
Thank you.
As your description, it seems you want to maintain the NavigationView always in the Compact mode, you can implement this effect by overriding the widths at which the navigation view changes display modes using the CompactModeThresholdWidth and ExpandedModeThresholdWidth properties.
You can try to configure your NavigationView as the following code,
<NavigationView CompactModeThresholdWidth="280" ExpandedModeThresholdWidth="2000"/>
You can set any CompactModeThresholdWidth property value smaller than the minimum default UWP app window width and the ExpandedModeThresholdWidth property value larger than the maximum window width.
More details, please see the NavigationView display modes topic.

Windows form with a transparent background that can be clicked through

INTRODUCTION
Using C# or VB.NET. I'm trying to make a form's background transparent; this form will be overlaped to other window, it will be a top-most window, so the transparent form (and its controls) must have the ability that they must not receive focus and they must can be clicked trough, this means if for example I perform a left-click on the transparent background, then the window on background of that (in the Z-order window) is the window that must receive the click instead.
Notes:
For avoiding the focus I'm overriding the CreateParams property as explained here.
For making my form transparent, I'm calling Win32 DwmExtendFrameIntoClientArea function and also using SharpDX library as explained here. But I think this really doesn't matter with the question itself.
PROBLEM
I'll show a demostration of what I mean using images. Here below is a image of a form (with no transparency, just to simplify understanding) overlapped to a window of a text editor program; note that my form doesn't receive focus. Well, the problem is when I do click on the form's background (or one of its controls) the window on background (the text editor window) still have focus but it can't receive the click.
Here is the same image of above but with a transparent form:
RESEARCH
I'm not really sure about what to investigate, so I'm going blind trying to find something useful in a trial-and-error stage by overriding the Window procedure (WndProc) of the transparent form to test related windows messages, like WM_NCHITEST or WM_MOUSEACTIVATE message as said here:
Windows form with a transparent background that cannot be clicked through
Make a form not focusable in C#
How do I create an "unfocusable" form in C#?
You can do this by sending click (mouse up & mouse down) messages to the window underneath the transparent window using WinAPI.
PostMessageA
You'll need to find the window underneath the point you require.
WindowFromPoint
You'll have to translate the position of the click events accordingly since messages are processed based on relative window position, not absolute screen position.
I actually did this quite successfully to automatically play a facebook game many years ago.
Check the RAD designer in Visual Studio.
Is the label docked to fill?
Where is the main form clickable?
The transparent color is click-though in the main parent, however, components will still retain clicks.

How to disable a Grid (Panel) in XAML Metro app?

I want to emulate modal dialog in XAML Metro App.
So I was going to set .IsEnabled = false on all controls apart from the one which will pose as a modal dialog.
Apparently IsEnabled not in Grid not in Panel not in FrameworkElement. How to disable it not making a user control out of it?
I guess Sinofsky cut so many corners that the whole thing is now more like an Escher staircases. I am loosing my faith. Please help
Sorry, I am a little late to the party...
Here is how I created a modal popup - I used a popup dialog where the top and bottom portions are transparent so that anything behind it will show through. When the popup is opened, I set its size to cover the entire screen.
The top and bottom portions of the popup also are set to autosize (height = *), so that they fill up the entire top and bottom of the screen. This prevents any input from going into the grid underneath.
Here is a screen shot of my popup in Visual Studio:
The popup is a grid with 5 rows, 3 for the dialog itself and 2 for the transparent top and bottom.
Here is how the popup looks in my app. Obviously the grid shows through the transparent top and bottom. Since the popup fills the entire screen, any input (keyboard or mouse) goes to it rather than the grid underneath, making the popup act like a modal dialog.
Be warned though that with this strategy, you have to handle these events:
Screen resizes (full screen, snapped view, filled view) - you need to resize the popup to fit within each of the view states
Screen rotation - again, you have to handle resizing here
Keyboard popup - you need to shift the popup up so that the onscreen keyboard does not interfere with it.
Set IsHitTestVisible = false on the background content.
Additionally you could set focus to something in your modal layer root and set TabNavigation to Cycle on the modal layer root to make sure that users can't tab/shift+tab out of it. Also make sure the modal layer is all hit test-solid - e.g. Transparent or has some other fill so users can't click through it.
Also make sure no Popups show while your modal layer is visible.
Unfortunately no one seems to know (except Mr Skakun who gave wrong answer and never bothered to revise it).
Hence my solution (the simplest) is to make the element in question Hidden - I cant find any other ways to 'disable' a grid.
If I wanted to disable it correctly I would have to write a recursive function to find all FrameworkElements in the grid children and set IsEnabled = false though.

What is the purpose of Popup in XAML Metro apps?

I needed a modal dialog for my app but it appeared there is nothing like that in XAML Metro app. Someone suggested a popup.
I tried and it appeared that underlying UI still responsive.. so a Popup is not modal.
I thought OK may be its purpose is to be a popup in the center of the screen regardless the other layout and it appeared - not. Popup is bound to a layout as everything else. if it is in a grid it will be placed in row 0 and column 0 not in the center..
So may be I missing something. please help to understand. I cant find any use for it different from what can be achieved by using Grid.
what is the purpose of Popup? how it different from any other content controls?
Differences:
You don't have to put it as a child of another control. Though in such scenarios you might get problems traversing the visual tree and focusing on a TextBox won't shift its contents so the virtual keyboard might cover its contents or its adorner contents might lose alignment to adorned controls not on the Popup.
Its content tree is rendered on top of any other content and (I believe) doesn't get clipped by parent control's Clip regions.
You usually need to set its Width and Height manually when first showing or when parent layout (or size) changes, especially in one of the most common scenarios when you set its Width and Height to the Width and Height of the parent (or the window).
That said - modal dialogs are bad UI and should be avoided. You can simply navigate to another page if you would otherwise want to display a dialog or use other approaches. There's (almost) nothing more annoying than displaying a modal dialog over UI that looks otherwise enabled but doesn't respond to input.
I needed a modal dialog for my app but it appeared there is nothing like that in XAML Metro app. Someone suggested a popup.
Since Windows 8.1, there is actually something similar to a modal dialog that you may want to look into:
It's called Flyouts.
Apparently a modal popup with custom content is missing in Windows 8.1. One possible workaround:
use a Popup control (per se not modal)
make the background semi-transparent
stretch it across the entire screen
place the actual popup content inside that container and leave some space around it
Now, the parent page is visible but dimmed, and it cannot be accessed as the Popup is covering it.

Categories

Resources