Scale user control in wpf?

I have several elements in my usercontrol. I put everything in the net. But now I'm trying, if the screen resolution changes, the window automatically scales. It just doesn't work. I have already used the viewbox, but not with the desired result. This is my user control:

<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 installed in the 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>

¨ Help someone help.

+3
source share
2 answers

Set the grid to a fixed width and height and set ViewBox.Stretch to Uniform. That should do it.

+1
source

The correct answer is more complicated than the solution you are looking for, but I will try to keep it short.

, , Grid , ( ) ViewBoxes. UserControl SizeChanged , UserControl .

, , WPF-.

0

All Articles