【发布时间】:2018-08-01 19:17:05
【问题描述】:
我正在使用以下代码在我的应用程序中旋转图像(使用 UserControl)。但它显示错误ConvertToBitmapImage 未在类型ImageControl 中找到。我该如何解决?
ImageControl XAML:
<UserControl x:Class="App1.ImageControl" ...>
<Image RenderTransformOrigin="0.5,0.5"
Source="{x:Bind ConvertToBitmapImage(UriPath), Mode=OneWay}"
Stretch="UniformToFill">
<Image.RenderTransform>
<CompositeTransform Rotation="{x:Bind Angle, Mode=OneWay}" />
</Image.RenderTransform>
</Image>
</UserControl>
ImageControl 背后的代码:
public string UriPath
{
get => (string)GetValue(UriPathProperty);
set => SetValue(UriPathProperty, value);
}
public static readonly DependencyProperty UriPathProperty = DependencyProperty.Register("UriPath", typeof(string), typeof(ImageControl), new PropertyMetadata(default(string)));
public double Angle
{
get => (double)GetValue(AngleProperty);
set => SetValue(AngleProperty, value);
}
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(ImageControl), new PropertyMetadata(default(double)));
public BitmapImage ConvertToBitmapImage(string path) => new BitmapImage(new Uri(BaseUri, path));
【问题讨论】:
-
不记得是否可以将数据绑定到方法,但是您可以尝试创建另一个 DependencyProperty,然后用 ConvertToBitmapImage 将其包装在内部,但不确定是否可以使用
-
我刚刚复制粘贴了您的示例,它工作正常。也许创建一个新项目并做同样的事情?
-
@JetChopper 试过了。但没有运气。我的最低目标版本是 10240
标签: c# uwp windows-10-universal