我有下一个问题。我有一个用xaml定义的ItemsControl。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Button Grid.Row="0" ></Button>
<ItemsControl Grid.Row="1" x:Name="ItemsControl"></ItemsControl>
</Grid>
在代码隐藏中,我将这个ItemsControl填充按钮。
public Window1()
{
InitializeComponent();
var list = new List<Button>();
list.Add(new Button() { Name = "btn1", Visibility = Visibility.Visible});
list.Add(new Button() { Name = "btn2", Visibility = Visibility.Collapsed});
list.Add(new Button() { Name = "btn3", Visibility = Visibility.Collapsed});
ItemsControl.ItemsSource = list;
}
现在,当渲染按钮时,高度非常小。我希望按钮在ItemsControl的最大高度呈现。有办法吗?
答案 0 :(得分:1)
尝试这个答案,我有一个去,它很好地工作:D
Stretching controls to fill ItemsControl
不要忘记<RowDefinition Height="*" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Row="0" ></Button>
<ItemsControl Grid.Row="1" x:Name="ItemsControl">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>