简体   繁体   English

从UserControl调用函数-UWP C#

[英]Call a function from UserControl - UWP C#

I'm using below code for rotate an image in my app (using UserControl). 我正在使用以下代码在我的应用程序中旋转图像(使用UserControl)。 But it shows an error ConvertToBitmapImage was not found in type ImageControl . 但它显示错误在ImageControl类型中找不到ConvertToBitmapImage How can I resolve it? 我该如何解决?

The ImageControl XAML: 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>

The ImageControl Code Behind: 背后的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));

You can not use {x:Bind} to bind a Function until Windows 10, version 1607. See the Functions in binding paths Note part: 在Windows 10版本1607之前,不能使用{x:Bind}来绑定功能。请参见绑定路径中功能注意部分:

To use functions with {x:Bind}, your app's minimum target SDK version must be 14393 or later. 要将功能与{x:Bind}一起使用,您应用的最低目标SDK版本必须为14393或更高版本。 You can't use functions when your app targets earlier versions of Windows 10. 当您的应用程序针对Windows 10的早期版本时,您将无法使用功能。

So you should either change your app min target version to 14393 or later, or don't use the x:bind function. 因此,您应该将应用的最低目标版本更改为14393或更高版本,或者不要使用x:bind函数。

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

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