탭이있는 창이 있습니다. 탭 중 하나에 다음과 같은 레이아웃이 있습니다. (실제로는 더 복잡하고 4 개의 텍스트 상자가 연속적으로 있고 더 많은 행이 있습니다.) 어떻게 세 번째 텍스트 상자의 레이블 너비가 위의 텍스트 상자 너비인지, 즉 그것들을 올바르게 정렬 시켰습니까? 문제는 WPF가 텍스트를 입력 할 때 세 번째 텍스트 상자를 넓히는 것입니다. 크기에 하드 코딩 된 숫자를 사용하면 WPF의 모든 목적을 무효화합니다. Windows Forms에서 WPF보다 10 배 더 빠릅니다.어떻게 wpf에서 텍스트 상자를 고정시킬 수 있습니까?
연속 된 작은 텍스트 상자의 각 집합에 대해 눈금을 사용하는 것보다 눈에 띄는 큰 텍스트 상자를 건너 뛰는 것보다 더 나은 방법이 있습니까?
alt text http://img28.imageshack.us/img28/3958/wpfanchor.png
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="3"/>
</Style>
<Style x:Key="SmallTextBox" TargetType="{x:Type TextBox}"
BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Width" Value="50"/>
</Style>
</Window.Resources>
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Left"
Width="{Binding ElementName=grid,Path=ActualWidth}"
Grid.IsSharedSizeScope="True">
<Grid Name="grid" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="c1"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="c2"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Foo:"/>
<TextBox Grid.Column="1" Style="{StaticResource SmallTextBox}"/>
<Label Grid.Row="1" Content="Foobar:"/>
<TextBox Grid.Row="1" Grid.Column="1"
Style="{StaticResource SmallTextBox}"/>
</Grid>
<TextBox Grid.Row="1"/>
<Grid Name="grid2" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="c1"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="c2"/>
</Grid.ColumnDefinitions>
<Label Content="Bar:"/>
<TextBox Grid.Column="1" Style="{StaticResource SmallTextBox}"/>
</Grid>
</StackPanel>
</Window>
편집 : 4 행 하나의 그리드있을 것
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="3"/>
</Style>
<Style x:Key="SmallTextBox" TargetType="{x:Type TextBox}"
BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Width" Value="50"/>
</Style>
</Window.Resources>
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Left"
Width="{Binding ElementName=grid,Path=ActualWidth}">
<Grid Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Foo:"/>
<TextBox Grid.Column="1" Style="{StaticResource SmallTextBox}"/>
<Label Grid.Row="1" Content="Foobar:"/>
<TextBox Grid.Row="1" Grid.Column="1"
Style="{StaticResource SmallTextBox}"/>
<TextBox Grid.Row="2" Grid.ColumnSpan="2"/>
<Label Grid.Row="3" Content="Bar:"/>
<TextBox Grid.Row="3" Grid.Column="1"
Style="{StaticResource SmallTextBox}"/>
</Grid>
</StackPanel>
</Window>
이것은 작동하지 않습니다. 세 번째 텍스트 상자에 일부 텍스트를 입력하면 텍스트가 더 넓어집니다. –