우리는 다양한 요소와 DataGrid가 포함 된 양식을 가지고 있습니다. 목록 상자가 스크롤 뷰어에 포함되어 있으면 창 크기를 늘리면 모두 잘됩니다. 창 크기를 줄이면 목록 상자의 높이가 그대로 유지되고 세로 스크롤 막대가 활성화됩니다. 목록 상자에서 높이 바인딩을 제거하면 목록 상자는 필요한 최대 높이로 이동합니다. 우리가 원하는대로 모든 국경에서 목록 상자를 사용하지 않으면.ListBox 또는 ScrollViewer의 다른 항목 컨트롤
다음 코드를 사용하여 문제를 시뮬레이션 할 수 있습니다.
<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="150"
Width="525">
<Grid
Margin="10">
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Border
x:Name="border"
MinHeight="40" />
<ListBox
Height="{Binding ElementName=border, Path=ActualHeight}">
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
</ListBox>
<ToolBar
Grid.Row="1">
<Button
Content="Add" />
</ToolBar>
</Grid>
</ScrollViewer>
</Grid>
</Window>
ListBox가 없을 때 테두리와 같은 방식으로 ListBox의 크기를 조정하려면 어떻게해야합니까? 당신이 찾고있는,하지만 난
<ListBox HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
는 당신이 필요로 수 있습니다 생각하지 100 % 확실
여백이 0.1로 설정된 경우에도이 솔루션이 작동합니다. 왜 이것이 효과가 있는지에 대한 설명이 있습니까? –
오류, 정말 죄송하지만 나도 당신의 경우 어떻게 작동하는지 모르겠다. 그것은 너비가 설정되지 않은 경우에도 텍스트 상자가 성장하지 못하도록 막으려 고 할 때 그물에서 발견 된 해킹입니다. 링크를 다시 찾으려고했는데이 사이트에서 나온 것 같습니다. http://stackoverflow.com/questions/386039/ – dnr3