【问题标题】:Xamarin Circle image buttonXamarin 圆圈图像按钮
【发布时间】:2017-03-10 17:53:25
【问题描述】:

我用的是circleImage

xmlns:ic="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions"

在我的 xaml 文件中。

我想要做的是插入

<ic:CircleImage 
    x:Name="userProfileImage"
    HeightRequest="50"
    WidthRequest="50"
    Aspect="AspectFill"
    Source="{Binding post.uploader.userProfile.userThumbnail}"
/>

按钮属性下的这张图片。

但如果我这样做(下)

<Button Clicked="OnUserInfoClicked">
    <Button.Image>
        <ic:CircleImage 
            x:Name="userProfileImage"
            HeightRequest="50"
            WidthRequest="50"
            Aspect="AspectFill"
            Source="{Binding post.uploader.userProfile.userThumbnail}"
        />
    </Button.Image>
</Button>

然后,我得到这个错误。

No property, bindable property, or event found for 'image'

我做错了什么?以及如何解决?

【问题讨论】:

    标签: c# xamarin xamarin.forms circleimage


    【解决方案1】:

    您尝试做的事情是不可能的。但是,如果您只想点击图片并执行操作,为什么不直接使用 TapGesture?

    <ic:CircleImage 
        VerticalOptions="Center"
        x:Name="userProfileImage"
        HeightRequest="50"
        WidthRequest="50"
        Aspect="AspectFill"
        Source="{Binding post.uploader.userProfile.userThumbnail}">
    
        <Image.GestureRecognizers>
            <TapGestureRecognizer Tapped="OnUserInfoClicked" />
        </Image.GestureRecognizers>
    </ic:CircleImage>
    

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      对于那些将来遇到此问题的人 - 如果您不需要使用 CircleImage 对象,Xamarin 的默认按钮通过将 CornerRadius 设置为图像高度的一半来获得圆形支持。

      <ImageButton
          x:Name="userProfileImage"
          HeightRequest="50"
          WidthRequest="50"
          Aspect="AspectFill"
          CornerRadius="25"
          BackgroundColor="White"
          Source="{Binding post.uploader.userProfile.userThumbnail}"
      />
      

      如果需要,您还可以添加 BorderColorBorderRadius 使其弹出更多:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多