如果我理解正確,可以使用Auto
,然後將MaxHeight
屬性綁定到Grid
的Height
。也許是這樣的:
MaxHeightConverter.cs:
public class MaxHeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
throw new ArgumentException("MaxHeightConverter expects a height value", "values");
return ((double)value/2);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
MyWindow.xaml:
...
xmlns:converters="clr-namespace:MyApp.Namespace"
...
<Window.Resources>
<converters:MaxHeightConverter x:Key="MaxHeightValue" />
</Window.Resources>
<Grid x:Name="root">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions>
<WrapPanel >
<WrapPanel.MaxHeight>
<Binding Converter="{StaticResource MaxHeightValue}" ElementName="root" Path="ActualHeight" />
</WrapPanel.MaxHeight>
</WrapPanel>
</Grid>
...
希望這有助於。
感謝。按照我想要的方式工作。我只需要在'MaxHeightConverter'中將演員從'(int)'改成'(double)'。 – Onur
Hoot!謝謝。這工作。 –