繁体   English   中英

从UserControl调用函数-UWP C#

[英]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));

在Windows 10版本1607之前,不能使用{x:Bind}来绑定功能。请参见绑定路径中功能注意部分:

要将功能与{x:Bind}一起使用,您应用的最低目标SDK版本必须为14393或更高版本。 当您的应用程序针对Windows 10的早期版本时,您将无法使用功能。

因此,您应该将应用的最低目标版本更改为14393或更高版本,或者不要使用x:bind函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM