【问题标题】:How to resize the Image control to fill horizontally and vertically resize the same amount如何调整图像控件的大小以水平和垂直填充调整相同的量
【发布时间】:2017-09-01 13:07:26
【问题描述】:

我想调整图像控件的大小,以便填充宽度和等量的高度。结果将是一个正方形。

如果我需要继承图像控件,我应该覆盖什么。

【问题讨论】:

    标签: image xamarin xamarin.forms resize


    【解决方案1】:

    根据您的要求,您的意思是希望 Image 控件具有相同的 WidthRequest 和 HeightRequest 值。你可以调整它的大小吗?

    您不需要重写图像控件,只需使用数据绑定将 WidthRequest 和 HeightRequest 绑定到相同的值。

    例如:

    <Image BindingContext="{x:Reference MySlider}" x:Name ="MyImg" WidthRequest="{Binding Value}" HeightRequest="{Binding Value}" BackgroundColor="Red"></Image>
    
    <Slider Grid.Row="1" x:Name="MySlider" Maximum="360"></Slider>
    

    enter image description here

    【讨论】:

    • 你的意思是如果我有一个滚动视图,其中图像托管在里面。我想让图像填充滚动视图的整个宽度,并且高度与自身的宽度相同。
    • U也可以将自身属性“WidthRequest”绑定到HeightRequest,并设置WidthRequest值填满整个宽度
    猜你喜欢
    • 2013-02-17
    • 1970-01-01
    • 1970-01-01
    • 2015-10-06
    • 2013-06-23
    • 2013-03-19
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    相关资源
    最近更新 更多