我正在製作WPF中的多選項卡應用程序,並且我想在選項卡的網格中製作一個水平居中的文本框。該選項卡控件當前被拉伸以適應窗口大小,因此如果窗口被調整大小/最大化,應用程序也將更改大小。如果我按下設計器中的「水平居中」按鈕,則會將文本框的方式置於右側。我在這裏做錯了什麼?拉伸選項卡控件中的中心文本框
下面是應用程序的XAML代碼至今:
<Window x:Class="GUI_Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GUI_Test"
mc:Ignorable="d"
Title="MainWindow" Height="524" Width="996.432">
<Grid>
<TabControl x:Name="tabControl" HorizontalContentAlignment="Center">
<TabItem x:Name="Home" Header="Home" Width="150">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem x:Name="Dictionary" Header="Dictionary" Width="150">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem x:Name="Search" Header="Search" Height="20" Width="150">
<Grid Background="#FFE5E5E5">
<TextBox x:Name="textBox" HorizontalAlignment="Center" Height="23" Margin="524,105,204,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="250"/>
</Grid>
</TabItem>
<TabItem x:Name="About" Header="About" Height="20" Width="150">
<Grid Background="#FFE5E5E5"/>
</TabItem>
</TabControl>
</Grid>
</Window>
我關注的「搜索」選項卡上,在這一刻。當窗口展開時,文本框(以及其他任何元素)也需要移動,所以我不能只計算中點並設置尺寸。我會做類似MarginLeft = MainWindow.getWidth/2
或類似的東西,但是既沒有MarginLeft
也沒有MainWindow
有任何可編輯的屬性。 我也嘗試在選項卡中使網格佈局不同,但它不允許我使用。
請給我們展示一些代碼。請參閱http://stackoverflow.com/help/mcve –
謝謝。它已被編輯。對不起,我不太流利的StackOverflow的規則呢:) – mmf1102
從文本框中刪除邊距。 –