【发布时间】:2016-01-04 13:46:53
【问题描述】:
在我的 UWP 应用的 DataTemplate 中,我想将矩形的高度设置为图像高度的百分比。
我的代码如下所示。
<DataTemplate
x:Key="FlipViewTemplate">
<Grid>
<Image
x:Name="image"
Margin="20"
Source="{Binding fullImgUrl}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
<Rectangle
Height="{Binding
Converter={StaticResource PercentageConverter},
ElementName=image,
Path=ActualHeight,
ConverterParameter=0.2}"
Fill="#FFEA1E1E"
VerticalAlignment="Bottom" />
</Grid>
</DataTemplate>
我的转换器也是这样的
public class PercentageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return System.Convert.ToDouble(value) *
System.Convert.ToDouble(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
我的问题是转换器中应该是图像实际高度的值始终为 0。
【问题讨论】:
标签: xaml uwp percentage ivalueconverter