3

我的用户控件中有多个项目。我把所有东西都放在一个网格里。但现在我正在尝试,如果我的屏幕分辨率发生变化,窗口会自动缩放。这只是行不通。我已经使用了 viewbox,但没有得到想要的结果。这是我的用户控件:

<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>

这个用户控件设置在一个窗口中:

<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>

¨请有人帮忙。

4

2 回答 2

1

将 Grid 设置为固定的 Width 和 Height,并将 ViewBox.Stretch 设置为 Uniform。那应该这样做。

于 2011-05-05T18:12:49.793 回答
0

The correct answer likely is more complicated than the solution you seek, but I'll try to keep it short.

To do what you want, in my experience your best bet is to use a Grid as your primary initial element and then situate your controls within that Grid (or other Grids inside of it) and wrap the individual controls in ViewBoxes. After that tie the UserControl SizeChanged event to a method that forces the height and width of the UserControl to maintain an appropriate ratio.

That's the best way I have found to handle it on my WPF UIs.

于 2014-07-10T22:05:12.453 回答