2

在我的 XAML 中,我有一个列表视图。列表视图的项目模板包含一个网格。这个网格有 4 列和 2 行。像这样:
xaml 项目模板

我希望左列填充图像和图像下方的彩色条。我的核心问题是图像大部分时间会决定项目的高度。虽然图像最大高度应该由项目的其余部分定义。所以最小100(网格MinHeight="125"-Height="25"矩形)。如果文本使项目变大,则更大。但是文本应该定义项目的高度。不是图像。

我当前的 xaml 如下:

<Grid MinHeight="125">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto" />
        <ColumnDefinition Width="2*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="48" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Width="100">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="25" />
        </Grid.RowDefinitions>
        <Image Grid.Row="0" Source="{Binding Path=BitmapImage}" Stretch="UniformToFill" />
        <Rectangle Grid.Row="1">
            <Rectangle.Fill>
                <SolidColorBrush Color="{Binding Path=Color}" />
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
    <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Name}" FontWeight="ExtraBold" TextWrapping="Wrap" FontSize="16" />
    <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Description}" TextWrapping="Wrap" FontSize="20" />
    <TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="2" Text="{Binding Path=Type}" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" FontSize="20" Margin="5" />
    <TextBlock Grid.Row="0" Grid.Column="3" Text="{Binding Path=Distance, Converter={StaticResource DistanceConverter}}" FontSize="16" />
    <Image Grid.Column="3" Grid.RowSpan="2" Source="/Images/appbar.next.rest.png" Stretch="Fill" Width="24" Height="24" />
</Grid>
4

1 回答 1

0

http://darutk-oboegaki.blogspot.com/2011/07/binding-actualheight-and-actualwidth.html包含有关如何执行此操作的信息,说明在 Silverlight 中ActualHeight通常给出的值是0.

从那里,如果您需要减去 25 个像素,您可以:

  • 编写转换器(实现的对象System.Windows.UI.Xaml.Data.IValueConverter
  • 将转换器的实例添加到页面/窗口的资源中。
  • 添加Converter={StaticResource MyConverter}, ConverterParameter=25到您的绑定中。

希望有帮助:)

于 2012-11-13T12:22:26.437 回答