How can I maximize a WPF page when the application starts? - c#

I have a simple WPF application with two xaml Pages. I'd like the app opening with the maximum size of the screen.
I've found only answers about WPF Windows, but for Pages there is not a "WindowState" property.
Thanks a lot!

In your Xaml window definition simply define:
WindowStartupLocation="CenterScreen" WindowState="Maximized"

You could set the Width and Height property manually according to your current Screen Resolution from here
System.Windows.SystemParameters.PrimaryScreenWidth;
System.Windows.SystemParameters.PrimaryScreenHeight;

Related

Setting size of Application Icon in WPF

I have a code wherein i put an image on my Application icon:
Title="Test WPF" Height="600" Width="800" WindowStartupLocation="CenterScreen" Closing="WindowClosing" Icon="ICON.PNG"
I know that the icon size is like 12 x 12 or 24 x 24.
Is it possible to have the Application Icon customize on size? like 40 x 24?
You can use the WindowChrome class to customize the non-client area of a window. In this page there is a section specifically mention the application icon and title.
The application icon and title are not displayed by the WindowChrome class; they have to be added to the border as custom content.
This is an example on how to do that.

Popup dimensions on screen

I thought I understood the WPF content scaling system but ran into an issue that's mysterious to me. I have a very simple popup that is supposed to be used as a loupe that opens on top of an image when the user clicks the image. The XAML is this:
<Popup Name="LoupePopup" AllowsTransparency="True" IsOpen="False" StaysOpen="True">
<Border BorderThickness="2" BorderBrush="Azure" />
</Popup>
In code behind, I then tie the popup's placement to an image that is already showing when the popup is opened. I set the loupe size to half the size of the image with this code:
LoupePopup.PlacementTarget = FullImg;
LoupePopup.Placement = PlacementMode.Relative;
LoupePopup.Width = FullImg.ActualWidth / 2;
LoupePopup.Height = FullImg.ActualHeight / 2;
Further code then moves the loupe along with MouseMove, but that does not really relate to the issue here: I'd expect the loupe to be exactly half the width/height of the image, but it is not - it is quite a bit larger (by about 18%). I verified the actual image size and the actual size of the window on which it is displayed, as well as the mouse coordinates. Those dimensions/point coordinates all made perfect sense, but why would the popup not use the same width/height scaling as the other elements here?
For clarification: The image covers 80% or so of the screen, so this is not just an issue of a few pixels. The window is a child window created in code, and the popup is defined in the XAML of the main window, but both windows are set to full screen size.
Appreciate your thoughts!
Maybe it is so because border thickness is not taking into account when calculating LoupePopup size
or default margin and padding of popup or image
I'm not sure, but I think you should have a look at the Stretch property of the image. If you have a width and a height defined on the image the ActualWidth/-Height are influenced by the Stretch property. Setting it to Fill makes the ActualWidth/-Height equal to the defined Width and Height.
After trying more options I had to realize that the child-versus main window aspect caused the issue. The image was showing in a child window; the popup was defined in the main window. After moving the popup XAML to the child window, the popup dimensions were correct.
Not sure I understand why (both windows have the full screen dimensions and should use the same scaling, but at least this solves my issue. Thanks for trying to help!

Automatic button scaling based on window size C#/XAML

i'm fairly new at this so i apologize in advance if i say anything stupid.
I am making a UI in WPF that consists of 8 buttons to open various programs set on my computer. Currently i am trying to get the buttons in the UI to scale based on the detected window size.
The problem i am having is trying to get the calculations done in the C# code to link over to the scale transform option for the buttons in XAML.
I have searched high and low to find a solution but i still cannot find a way to link the value to XAML. Does anyone know of a guide for something like this and should it be done using a converter?
Thanks for any help.
When you need your content to autoscale, put it all into a ViewBox control.
<Window>
<Viewbox>
<Grid x:Name = rootGrid>
</Grid>
</Viewbox>
</Window>
Now everything will magically fill to the window size and scale! Instant awesomeness for your app.

Creating a full-screen option from WPF tab controls

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.

How to Set Screen Resolution At run time in wpf

i have a problem guys i made a wpf applications its running well but when i run the application on different screen resolution, then the controls(i.e. the size) added in the xbap page changes. So i want to get the current screen resolution and make the size of controls unchangable.Can anyone help me out.
thanks in advance Radhe Govind
<Window x:Class="MedSelectNew.ImageSelection"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MedSelectNew"
Title="ImageSelection" WindowState="Maximized" Loaded="Window_Loaded" ShowInTaskbar="False" WindowStyle="None" Background="Black" Width="{x:Static SystemParameters.PrimaryScreenWidth}" Height="{x:Static SystemParameters.PrimaryScreenHeight}" KeyDown="Window_KeyDown">
You can get the DPI-adjusted primary screen resolution from these properties:
SystemParameters.FullPrimaryScreenHeight
SystemParameters.FullPrimaryScreenWidth
It is not clear to me why you would want this, however. If you want your controls to be smaller when your window is smaller, just use WPF's layout capabilities along with ViewBox. If not, just give all your controls the same size. Either way I don't see how the current screen resolution comes into the picture.

Categories

Resources