2011-05-05 147 views
3

我在我的用戶控件中有多個項目。我把所有東西放在一個網格中。但現在我正在嘗試,如果我的屏幕分辨率發生變化,窗口會自動縮放。這只是不起作用。 我已經使用了viewbox,但沒有想要的結果。 這是我的用戶:在wpf中縮放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> 

該用戶控件的窗口中設置:

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

請別人幫助。

+0

你能否在視覺上描述你想如何擴展? – 2011-05-05 19:05:54

回答

1

將網格設置爲固定的寬度和高度,並將ViewBox.Stretch設置爲均勻。這應該做到這一點。

+0

我做到了。但是,如果我改變屏幕的分辨率(當使用投影儀時),網格不會填滿整個屏幕... – Ruben 2011-05-05 18:26:17

+0

@Ruben:投影儀不是你應該使用的語言之外,它已被髮明在(這是一個愚蠢的英國主義)'正確'的詞將是「投影儀」。 – 2011-05-05 22:13:07

+0

@Ruben:多數民衆贊成在這奇怪的..但窗口仍然最大化在新的決議(並不重疊多個屏幕)? (我也會使用「beamer」,但是,第二語言,雖然) – Jens 2011-05-06 06:09:35

0

正確的答案可能比您尋求的解決方案更復雜,但我會盡量保持它的簡短。

按我的經驗做你想做的事情,你最好的選擇是使用網格作爲你的主要初始元素,然後將你的控件放置在該網格(或其內部的其他網格)中,並將單個控件包裝在ViewBoxes中。之後,將UserControl SizeChanged事件綁定到強制UserControl的高度和寬度保持適當比例的方法。

這是我發現在我的WPF UI上處理它的最佳方式。