[英]Call a function from UserControl - UWP C#
我正在使用以下代码在我的应用程序中旋转图像(使用UserControl)。 但它显示错误在ImageControl
类型中找不到ConvertToBitmapImage
。 我该如何解决?
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.