简体   繁体   English

如何使用xamarin表格为Windows 8.1(无Silverlight)手机圆角矩形边缘

[英]How to round rectangle edges for a windows 8.1 (no silverlight) phone using xamarin forms

I am using Xamarin forms BoxView control and would like to round off the edges in Windows Phone 8.1 (no silverlight). 我正在使用Xamarin表单BoxView控件,并希望在Windows Phone 8.1(没有silverlight)的边缘圆。 For this I am rendering the control in my windows phone project and setting the radius however it doesn't seem to be doing anything. 为此我在windows phone项目中渲染控件并设置半径,但它似乎没有做任何事情。 Below is the renders code I am using: 下面是我正在使用的渲染代码:

[assembly: ExportRenderer(typeof(RoundedBox), typeof(RoundedBoxRenderer))]

namespace MyProject.WinPhone.Renderer
{
    public class RoundedBoxRenderer : BoxViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
        {
            base.OnElementChanged(e);

            var boxRenderer = e.NewElement;
            RoundedBox rb = (RoundedBox)this.Element;

            if (this.Control != null)
            {
                var boxStyle = new Style(typeof(RoundedBox))
                {
                    Setters = {
                        new Setter {Property = RoundedBox.BackgroundColorProperty, Value = rb.BackgroundColor}
                    }
                };

                SetRoundedBoxRadius();

                boxRenderer.Style = boxStyle;
            }
        }

        private void SetRoundedBoxRadius(double radius)
        {
            ((Windows.UI.Xaml.Shapes.Rectangle)this.Control).RadiusX = 50;
        }
    }
}

RoundedBox is the control I generated in my PCL project that inherits from BoxView RoundedBox 是我在PCL项目中生成的控件,它继承自BoxView

From my findings I don't see what im doing wrong since Xamarin converts the BoxView to a Rectangle shape in windows phones according to: 根据我的发现,我不知道我做错了什么,因为Xamarin根据以下内容将BoxView转换为Windows Phone中的矩形形状:

https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/renderers/ https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/renderers/

And this shape has the property RadiusX and RadiusY to set the borders radius: 此形状具有RadiusX和RadiusY属性来设置边框半径:

https://msdn.microsoft.com/library/windows/apps/br243371 https://msdn.microsoft.com/library/windows/apps/br243371

Any ideas as to what i'm missing? 关于我缺少什么的任何想法? Thanks! 谢谢!

Did you try setting the Stroke (color) and StrockThickness of your rectangle? 您是否尝试设置矩形的笔触(颜色)和StrockThickness According to your code, those are not set. 根据你的代码,那些没有设置。 Therefore, your rectangle has, in fact, no border. 因此,您的矩形实际上没有边框。

Hello Just update your SetRoundedBoxRadius function as mentioned below. 您好,只需更新您的SetRoundedBoxRadius函数,如下所述。 Your code will work. 你的代码会起作用。

private void SetRoundedBoxRadius()
        {
            ((Windows.UI.Xaml.Shapes.Rectangle)this.Control).RadiusX = 50;
            ((Windows.UI.Xaml.Shapes.Rectangle)this.Control).RadiusY = 50;
        }

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

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