2015-07-21 50 views
0

我在調整app.xaml窗體的主窗口大小時遇到​​問題:調整窗體大小後,表單內的對象(按鈕,組合框,文本框等)正在調整大小,隱藏或移動到窗體中的另一個位置。我只是想調整主窗口而不是其他對象。換句話說,我想取消鏈接這兩個(主窗口&其他對象)彼此。在完成之後,我可以調整主窗口大小,然後手動將對象移動到窗體中的新位置。下面給出了表單的代​​碼。在調整主窗口大小後,xaml表單中的對象正在被加密(調整大小或隱藏)?

<Window x:Class="WPFClient.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="550" Width="834" MaxHeight="550" MaxWidth="834" MinHeight="550" MinWidth="834"> 
    <Grid> 
     <Grid.Background> 
      <LinearGradientBrush> 
       <GradientStop Color="LightSlateGray" Offset="0"/> 
       <GradientStop Color="White" Offset="0.5"/> 
       <GradientStop Color="LightSlateGray" Offset="0.9"/> 
      </LinearGradientBrush> 
     </Grid.Background> 


     <Label x:Name="loginLabelUName" Height="25" HorizontalAlignment="Left" Margin="179,200,0,0" VerticalAlignment="Top" Width="70">User Name: 
     </Label> 
     <TextBox x:Name="loginTxtBoxUName" Height="23" Margin="277,200,313,0" VerticalAlignment="Top" /> 
     <Label x:Name="loginLabelIP" HorizontalAlignment="Left" Margin="179,232,0,255" Width="70">Service IP:</Label> 
     <TextBox x:Name="loginTxtBoxIP" Margin="277,232,313,0" Text="41.235.135.104" Height="23" VerticalAlignment="Top" /> 
     <Button x:Name="loginButtonConnect" Background="Transparent" Margin="277,0,313,222" Click="buttonConnect_Click" Height="23" VerticalAlignment="Bottom">Connect</Button> 
     <Label x:Name="loginLabelStatus" Height="44" VerticalAlignment="Bottom" FontFamily="Jokerman" FontSize="20" Foreground="White" HorizontalAlignment="Right" Width="167" Margin="0,0,40,71">Offline</Label> 
     <ComboBox x:Name="loginComboBoxImgs" HorizontalAlignment="Right" Margin="0,200,197,222" Width="98" Background="Transparent" /> 
     <Label x:Name="loginLabelTitle" Height="57" FontFamily="Jokerman" FontSize="25" Foreground="White" Margin="16,16,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="293">WCF/WPF Chat App.</Label> 
<Polyline x:Name="loginPolyLine" StrokeThickness="2" Stroke="White" Points="140,90 140,300 700,300 700,90 140,90" Margin="-9,42,116,165" /> 



     <ListBox x:Name="chatListBoxMsgs" Margin="10,62,167,84" /> 
    <ListBox x:Name="chatListBoxNames" HorizontalAlignment="Right" Margin="0,62,10,84" Width="139" /> 
    <CheckBox x:Name="chatCheckBoxWhisper" Height="15" HorizontalAlignment="Right" Margin="0,37,10,0" VerticalAlignment="Top" Width="120" Foreground="White" FontSize="12">Whisper Mode</CheckBox> 
    <TextBox x:Name="chatTxtBoxType" Height="39" Margin="10,0,313,9" VerticalAlignment="Bottom" /> 
    <Button x:Name="chatButtonSend" Click="chatButtonSend_Click" Height="39" Margin="0,0,167,9" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="136">Send</Button> 
    <Button x:Name="chatButtonDisconnect" Click="chatButtonDisconnect_Click" Height="39" HorizontalAlignment="Right" Margin="0,0,10,9" VerticalAlignment="Bottom" Width="139">Disconnect</Button> 
    <Image x:Name="chatCurrentImage" HorizontalAlignment="Left" Margin="10,0,0,0" Stretch="Fill" Width="60" Height="70" VerticalAlignment="Top" /> 
    <Label x:Name="chatLabelCurrentUName" Height="23" HorizontalAlignment="Left" Margin="87,10,0,0" VerticalAlignment="Top" Width="85" Foreground="White"></Label> 
    <Label x:Name="chatLabelCurrentStatus" Height="23" Margin="87,37,0,0" VerticalAlignment="Top" Foreground="Green" HorizontalAlignment="Left" Width="85"></Label> 
    <Label x:Name="chatLabelWritingMsg" Height="30" Margin="10,0,167,49" VerticalAlignment="Bottom" Foreground="Gray"></Label> 
    <Button x:Name="chatButtonSendFile" Click="chatButtonSendFile_Click" Background="Transparent" Height="23" Margin="270,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="105">Send File</Button> 
    <Label x:Name="chatLabelSendFileStatus" Height="28" Margin="270,32,316,0" VerticalAlignment="Top"></Label> 
    <Button x:Name="chatButtonOpenReceived" Click="chatButtonOpenReceived_Click" Background="Transparent" Height="23" Margin="382,10,313,0" VerticalAlignment="Top">Open Received Files</Button> 



    </Grid> 
</Window>  
+0

您是否聽說過wpf中的相對大小[Relative](http://wpf.2000things.com/tag/star-sizing/)和[Relative sizing](http://www.codeproject.com/)文章/ 30904/WPF-Layouts-A-Visual-Quick-Start)可能會有所幫助 –

回答

0

發生這種情況的原因是因爲您明確地爲您的元素設置了Margin屬性。

Margin="277,232,313,0" 

這些利潤率是相對於母公司Grid。所以上面的代碼說:

將元素277從左邊,從頂部232,從右邊313和從底部0。

因此,當Grid得到調整大小時,這些邊距將被重新計算,從而搞砸了元素的位置。

爲了解決這個問題,你應該考慮使用相對於的定位。已經有了這個問題的答案here

0

我發現了一個簡單solution.when餘像選擇按鈕或...的物體,小鏈路圖標(類似於上述超鏈接圖標)出現在所述對象的每個邊緣(或在網格上在其周圍)。通過點擊這些圖標,可以將它們更改爲未鏈接鏈接情況。現在,當您要調整主窗口大小時,應該執行以下操作: 1.將所有對象移動到窗體中您想要的新位置。 2.一個接一個地選擇對象,然後單擊想要減小主窗口寬度或高度的側邊的鏈接圖標。例如,如果要從右側/右側減小窗口的寬度/高度,在下側,你應該取消鏈接每個「右/下」側鏈接圖標。 3.根據第二步示例,通過拖動邊緣來調整主窗口的寬度或高度。你可以看到大小調整窗口根本不影響其他對象。

相關問題