0
在用戶控件中,我放置了一個綁定到動態數據源的列表框。這個用戶控件將在一個彈出窗口中。我想要這個列表框可以填充窗口的剩餘空間。這裏是XAML中我嘗試:如何使listbox在其父級內可調整大小?
<ComboBox x:Name="cmbx1" Grid.Column="0" Grid.Row ="0" Margin="5"
Width="150" VerticalAlignment="Center" HorizontalAlignment="Left" SelectionChanged="filters_SelectionChanged">
......
</ComboBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Column="1" Grid.Row="0">
<Button Content="Test" Margin="5" Click="Button_Add" />
</StackPanel>
<DataGrid x:Name="ListGrid" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
......
</DataGrid>
<ComboBox x:Name="cmb2" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="5">
......
</ComboBox>
<ListBox x:Name="lstSharing" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,10,0"
Width="{Binding Width, ElementName=ListGrid}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<tkit:WrapPanel Orientation="Horizontal" MaxWidth="650" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="3" Width="Auto">
<CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" />
<TextBlock Text="{Binding ItemName}" Width="120" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我想它的高度和列表框的寬度可以設置動態的基於窗口的大小是什麼,項目綁定到列表框。但它不能正常工作。最初,列表框沒有滾動條,我需要手動調整窗口大小,以便顯示滾動條。我不能動態改變,所以我把MaxWidth = 600。否則,它總是在一行中顯示所有項目。
如何解決此問題?
謝謝。已經嘗試過了。然後,如果應用MaxWidth綁定,則在運行應用程序時,列表框內部沒有顯示任何內容。 – KentZhou 2013-03-19 16:27:18