Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale usercontrol in wpf?

Tags:

scale

wpf

items

i have multiple items in my usercontrol. I put everything in a grid. But now i am trying, if the resolution of my screen changes, the window scales automatically. This just doesn't work. I already used viewbox, but not with the wanted result. This is my usercontrol:

<UserControl x:Class="NewWPFVragenBeheer.Maak_toets.Views.ChangeCourse"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:converters="clr-namespace:NewWPFVragenBeheer.Converters"
                        mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="700"
            >

    <UserControl.Resources>
        <XmlDataProvider x:Key="Vakken"
                Source="C:\Users\Ruben\Desktop\Stage 26-04\stage_TFW\stage_TFW\NewWPFVragenBeheer\Data\Courses.xml"
                XPath="/Courses/Course"
           />

        <converters:RadioBoolToIntConverter x:Key="radioBoolToIntConverter" />
    </UserControl.Resources>

    <Viewbox Stretch="None">
        <Grid >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="722*" />
                <ColumnDefinition Width="254*" />
            </Grid.ColumnDefinitions>


            <Label Content="Maximale tijd:" Height="28" FontWeight="Bold" HorizontalAlignment="Left" Margin="12,28,0,0" Name="label1" VerticalAlignment="Top" Width="177"  />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="215,30,0,0" Text="{Binding Path=MaxTime}" VerticalAlignment="Top" Width="145" />

            <TextBox Height="23" HorizontalAlignment="Left" Margin="215,2,0,0" Text="{Binding Path=ExamName,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Name="textBox1"   VerticalAlignment="Top" Width="145" />
            <Label FontWeight="Bold" Content="Punten:" Height="28" HorizontalAlignment="Left" Margin="386,0,0,0" Name="label2" VerticalAlignment="Top" />
            <TextBox Height="23"  Text="{Binding Path=Score,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"  HorizontalAlignment="Left" Margin="567,2,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" />
            <Label Content="{Binding Path= FeedbackText, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Height="28" HorizontalAlignment="Right" Margin="0,153,527,0" Name="label3" VerticalAlignment="Top" Width="200" Foreground="#FFF50D0D" />

        </Grid>
    </Viewbox>
</UserControl>

this usercontrol is set in a window:

<Window x:Class="NewWPFVragenBeheer.MaakToetsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:view="clr-namespace:NewWPFVragenBeheer.Views"
        Title="MaakToetsDialog" 
        WindowStyle ="SingleBorderWindow"
        WindowState ="Maximized"
        WindowStartupLocation="CenterScreen"        
       >


    <view:MaakToetsView />
</Window>

¨please someone help.

like image 981
Ruben Avatar asked Mar 02 '26 07:03

Ruben


1 Answers

Set the Grid to a fixed Width and Height, and set ViewBox.Stretch to Uniform. That should do it.

like image 82
Jens Avatar answered Mar 04 '26 05:03

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!