我對WPF很新穎。我經常發現我的自我與得到了一堆的子控件相結合的寬度,以匹配特定父容器掙扎。作爲在以下幾點:子控件的寬度應該與父容器的寬度匹配
<ListBox x:Name="BrugereListBox" Grid.Column="0" Grid.Row="3" DataContext="{DynamicResource Brugere}"
ItemsSource="{Binding}"
PreviewMouseLeftButtonDown="BrugereListBox_MouseLeftButtonDown"
PreviewMouseMove="BrugereListBox_PreviewMouseMove"
>
<ListBox.ItemTemplate >
<DataTemplate >
<Border BorderBrush="Black" BorderThickness="1" Margin="2">
<StackPanel Orientation="Vertical" IsEnabled="True"
PreviewMouseLeftButtonDown="StackPanel_PreviewMouseLeftButtonDown">
<StackPanel Orientation="Horizontal" >
<Label>Navn</Label>
<TextBox Text="{Binding Name}"></TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label>Password</Label>
<TextBox Text="{Binding Password}"></TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label>Email</Label>
<TextBox Text="{Binding Email}"></TextBox>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在這種情況下,我感興趣的是得到的孩子的寬度所述的StackPanel:
<StackPanel Orientation="Horizontal" >
<Label>Navn</Label>
<TextBox Text="{Binding Name}"></TextBox>
</StackPanel>
到的
<ListBox x:Name="BrugereListBox"
任何通用的解決方案的寬度相匹配這樣的場景?
可能重複的[wpf邊框控件以跨越listboxItem的寬度](http://stackoverflow.com/questions/460812/wpf-border-control-to-span-the-width-of-listboxitem) – Dzyann 2015-08-19 19:56:02