這是一個相當簡單的問題,從技術上講這不是什麼大問題,但當我看到這個時,我的強迫症很刺痛。 我設計了一個基本的WPF應用程序,我無法弄清楚到底爲什麼按鈕和textboxs不正確alligning因爲可以在這個圖像(右下側)中可以看出: WPF對齊網格中的文本框和按鈕?
這是負責它的代碼:
<Grid Margin="283,365.288,18,10" Grid.ColumnSpan="2">
<Label Content="GUID" HorizontalAlignment="Left" Margin="0,0.998,0,0" VerticalAlignment="Top" Height="22.96"/>
<Label Content="UniqueID" HorizontalAlignment="Left" Margin="0,22.68,0,0" VerticalAlignment="Top" Height="25.516" Width="63.297"/>
<Label Content="Akt/GZ" HorizontalAlignment="Left" Margin="0,48.196,0,0" VerticalAlignment="Top" Height="25.516" Width="63.297"/>
<TextBox HorizontalAlignment="Left" Height="23.958" Margin="63.297,0,0,49.754" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Bottom" Width="125"/>
<TextBox HorizontalAlignment="Left" Height="23.958" Margin="63.297,0,0,25.796" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Bottom" Width="125"/>
<TextBox HorizontalAlignment="Left" Height="23.958" Margin="63.297,0,0,1.558" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Bottom" Width="125"/>
<Button Content="Search" HorizontalAlignment="Left" Margin="193.297,0.998,0,0" VerticalAlignment="Top" Width="60.703" Height="22.96"/>
<Button Content="Search" HorizontalAlignment="Left" Margin="193.297,25.236,0,0" VerticalAlignment="Top" Width="60.703" Height="22.96"/>
<Button Content="Search" HorizontalAlignment="Left" Margin="193.297,49.194,0,0" VerticalAlignment="Top" Width="60.703" Height="22.96"/>
<CheckBox Content="07" HorizontalAlignment="Left" Margin="259,5.498,0,0" VerticalAlignment="Top"/>
<CheckBox Content="10" HorizontalAlignment="Left" Margin="296.915,5.498,0,0" VerticalAlignment="Top"/>
<CheckBox Content="07" HorizontalAlignment="Left" Margin="259,29.736,0,0" VerticalAlignment="Top"/>
<CheckBox Content="10" HorizontalAlignment="Left" Margin="296.915,29.736,0,0" VerticalAlignment="Top"/>
<CheckBox Content="07" HorizontalAlignment="Left" Margin="259,53.694,0,0" VerticalAlignment="Top"/>
<CheckBox Content="10" HorizontalAlignment="Left" Margin="296.915,53.694,0,0" VerticalAlignment="Top"/>
</Grid>
無論哪種方式,我不太確定是什麼原因導致它漂移了一下。此外(如果有人問)我不知道爲什麼我用網格來分組這些對象,我搜索WPF中的對象分組,我發現了一些答案,但網格和Stackpanel似乎是最容易使用,但Stackpanel給了正確對齊內容時,我甚至會更頭痛。 如果您對移植有些批評,請隨時這樣做,我已經訂購了一些關於WPF設計的書籍,但我非常樂意並願意傾聽有經驗的開發人員並學習。
我爲「不問」的問題表示歉意,但我已經花了最後2天擺弄這些設置無濟於事,不會來到這裏,否則就會問。
謝謝
http://wpftutorial.net/LayoutProperties.html –
[WPF教程:佈局面板 - 容器](http://www.codeproject.com/文章/ 140613/WPF-Tutorial-Layout-Panels-Containers-Layout-Trans) 在這種情況下,網格是正確的選擇。但是你需要使用列和行。 –
@ValeraScherbakov謝謝你的鏈接,現在正在閱讀:) – Orbital