2016-07-06 161 views
0

我是新與WPF形式所以這可能很容易,但如何調整所有對象的我的WPF形式...時設置窗口最大化

我創建了一個新的WPF的形​​式,並添加12圖像。我設定了最大化的窗口,我相信它可以適用於任何顯示器上的視圖,對吧?如何讓我的對象轉換,以便在最大化模式下看起來大致相同?

第一張圖片是設計師看起來像的樣子,第二張是程序運行時的樣子。

In the designer: When running:

回答

0

顯然,你要舒展你的整個UI。然後ViewBox控件是非常有用的:

<Window ...> 
    <ViewBox> 
     <Grid Height="800" Width="600"> 
      <!-- Everything inside viewbox will be stretched as you resize window 
       Place you UI assuming you have virtual resolution 800x600 --> 
     </Grid> 
    </ViewBox> 
</Window> 
0

我建議你使用WrapPanel來佈置你的圖片:

<WrapPanel> 
<Image x:Name="b1" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png" Visibility="Hidden"/> 
    <Image x:Name="b2" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png"/> 
    <Image x:Name="b4" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png"/> 
    <Image x:Name="b3" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png" Visibility="Hidden"/> 
    <Image x:Name="b5" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png" Visibility="Hidden"/> 
    <Image x:Name="b6" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png"/>   
    <Image x:Name="y1" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="51" Source="yellowCircle.png"/> 
    <Image x:Name="y2" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="51" Source="yellowCircle.png" Visibility="Hidden"/> 
    <Image x:Name="y3" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="51" Source="yellowCircle.png"/> 
    <Image x:Name="y4" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="yellowCircle.png" Visibility="Hidden"/> 
    <Image x:Name="y5" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="yellowCircle.png"/> 
    <Image x:Name="y6" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="yellowCircle.png" Visibility="Hidden"/> 
</WrapPanel> 

WrapPanel如果沒有沒有足夠的空間自動換到新的生產線。

更新:

我做了一個測試5張圖片,但您可以12張圖像做。要做12張圖片,你應該添加12列。讓我給個例子:

<Window x:Class="SOWpfApplication.MainWindow" 
     <!--The code omitted for the brevity--> 
     > 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="2*"/> 
      <RowDefinition/> 
     </Grid.RowDefinitions> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
      </Grid.ColumnDefinitions> 
      <Image Source="/Images/Back.jpg" Stretch="UniformToFill"/> 
      <Image Source="/Images/Forward.jpg" Grid.Column="1" Stretch="UniformToFill"/> 
      <Image Source="/Images/Back.jpg" Grid.Column="2" Stretch="UniformToFill"/> 
      <Image Source="/Images/Back.jpg" Grid.Column="3" Stretch="UniformToFill"/> 
      <Image Source="/Images/Forward.jpg" Grid.Column="4" Stretch="UniformToFill"/> 
     </Grid> 

     <TextBlock Text="Time is up!" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="50"/>   
     <Button Margin="10" Grid.Row="2" HorizontalAlignment="Left" Height="42" Width="150" Content="Close" /> 
    </Grid> 
</Window> 
+0

這並沒有解決我遇到的問題。我會看看我是否可以爲我的問題添加屏幕截圖。 –

+0

我編輯了我原來的問題。我修正了第二部分。 –

+0

@NotSteve請參閱我的更新部分 – StepUp

0

我最常做的是要擴大,對頂部和右側選擇錨,因爲這通常是足夠的伸展我的目的部分的編輯。然而,隨着錨的發揮,這是什麼會讓你縮放你正在尋找。在你的情況下,你可能想要錨定你想縮放的所有東西的所有四個方面。

編輯

或者,你也可以選擇綿延水平和垂直對齊,這將導致拉伸爲好。請注意,只要確保使用邊距將圖像放置在所需的位置即可。

+1

如果你想擴展一切(看起來更大,以適應屏幕),你可以使用' ViewBox'。 – mechanic

0

嘗試設置高度&寬度屬性爲「自動」,這將自動調整窗體上的所有元素。

問候, 維沙爾