AComputer
AComputer

Reputation: 529

WPF and Screen Resolution

I am developing a WPF application in C#.net. I have a question regarding Window adjustment. In Some Screen Resolutions my main window is OK but in wide screen monitor and some other screen resolution window and controls in it are Cluttered.

Upvotes: 1

Views: 2923

Answers (2)

naqvitalha
naqvitalha

Reputation: 793

If you hard code Height and Width or, align elements only using margins you'll run into scaling problems with different resolutions. You need a clever grid layout where you only assign Row and Columns to controls and set their Horizontal and Vertical Alignments. Thus, even if the grid resizes the relative arrangement of elements will not alter and the layout will remain consistent. If you don't take advantage of higher resolutions in your application (like displaying more items) you may consider using Canvas inside a ViewBox which basically Scales to Fit everything.

Upvotes: 1

yo chauhan
yo chauhan

Reputation: 12315

Hi one of the simplest way to do that is do not set the width and Height of window and set the property SizeToContent=WidthAndHeight as

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" SizeToContent="WidthAndHeight">
<Grid Height="226">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>            
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

I hope this will help.

Upvotes: 1

Related Questions