我使用Xamarin.Forms
,我有Image
。我想與Corner Radius
和Border Width
對接。我可以做嗎 ?我嘗試使用Frame
。這很好,但它只有Border Width
= 1,我不能改變這一點。我知道Effect
,但我不想使用它們。我可以做它例如使用矩形或任何方式?Xamarin.Forms框架邊框寬度
2
A
回答
2
您可以使用效果創建自己的實現,也可以擴展FreshEssentials開放源代碼庫。他們有一個名爲AdvancedFrame的控件,它爲所有平臺上的Frame控件提供自定義渲染器。
如果您查看每個特定於平臺的項目,您會注意到AdvancedFrameRenderer
類爲創建圓角支持創建了更加複雜的路徑。你只需要深入到每個平臺上的Draw
方法(iOS,Android),並找出如何設置筆觸寬度。
從Android開始,最簡單的方法是在代碼中定義筆畫寬度(on this line)。您只需要在AdvancedFrame控件中爲該屬性創建一個屬性,以便每個控件都可以有不同的寬度。我不知道如何在iOS上設置筆觸寬度,但它使用UIBezierPath,它應該很容易修改。
1
你可以嘗試這樣的事情:
<Frame HasShadow="False" CornerRadius="25" Padding="2" BackgroundColor="#F69927">
<Frame HasShadow="False" CornerRadius="23" BackgroundColor="White" Padding="12">
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" VerticalOptions="Start">
<!-- Content -->
</StackLayout>
</Frame>
</Frame>
0
我試着用FrameRenderer跳舞Android和我找到了一些解決方案。 不好的一面是,要成爲MyFrameRenderer類中可見的邊框顏色,寬度和角半徑變量,我必須創建MyFrame:Frame類來僅影響我自己的框架類型。關閉夠我的目的......所以:
namespace PROJECT
{
public class MyFrame : Xamarin.Forms.Frame
{
public static float myFrameWidth = 2;
public static float myCornerRadius = 12;
public static Color myFrameColor = Color.Red;
public static Color myBackgroundColor = Color.Black;
public MyFrame() { }
}
}
...
[assembly: ExportRenderer(typeof(PROJECT.MyFrame), typeof(PROJECT.Droid.MyFrameRenderer))]
namespace PROJECT.Droid
{
class MyFrameRenderer : FrameRenderer
{
protected override void OnDraw(Android.Graphics.Canvas canvas)
{
// canvas contains image of standard outline
// to "hide" it, not efficent but sometimes "close enough solution"
// is to overlay that outline by new one in our's page background color
// then draw a new one in prefered style
// or... just draw thicker one over the old
var my1stPaint = new Android.Graphics.Paint();
var my2ndPaint = new Android.Graphics.Paint();
var backgroundPaint = new Android.Graphics.Paint();
my1stPaint.AntiAlias = true;
my1stPaint.SetStyle(Paint.Style.Stroke);
my1stPaint.StrokeWidth = MyFrame.myFrameWidth + 2;
my1stPaint.Color = MyFrame.myFrameColor.ToAndroid();
my2ndPaint.AntiAlias = true;
my2ndPaint.SetStyle(Paint.Style.Stroke);
my2ndPaint.StrokeWidth = MyFrame.myFrameWidth;
my2ndPaint.Color = MyFrame.myBackgroundColor.ToAndroid();
backgroundPaint.SetStyle(Paint.Style.Stroke);
backgroundPaint.StrokeWidth = 4;
backgroundPaint.Color = MyFrame.myBackgroundColor.ToAndroid();
Rect oldBounds = new Rect();
canvas.GetClipBounds(oldBounds);
RectF oldOutlineBounds = new RectF();
oldOutlineBounds.Set(oldBounds);
RectF myOutlineBounds = new RectF();
myOutlineBounds.Set(oldBounds);
myOutlineBounds.Top += (int)my2ndPaint.StrokeWidth+3;
myOutlineBounds.Bottom -= (int)my2ndPaint.StrokeWidth+3;
myOutlineBounds.Left += (int)my2ndPaint.StrokeWidth+3;
myOutlineBounds.Right -= (int)my2ndPaint.StrokeWidth+3;
canvas.DrawRoundRect(oldOutlineBounds, 10, 10, backgroundPaint); //to "hide" old outline
canvas.DrawRoundRect(myOutlineBounds, MyFrame.myCornerRadius, MyFrame.myCornerRadius, my1stPaint);
canvas.DrawRoundRect(myOutlineBounds, MyFrame.myCornerRadius, MyFrame.myCornerRadius, my2ndPaint);
base.OnDraw(canvas);
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Frame> e)
{
base.OnElementChanged(e);
}
}
}
相關問題
- 1. matplotlib邊框寬度
- 2. 部分寬度邊框
- 3. 減少邊框的寬度
- 4. CSS無邊框寬度
- 5. Xamarin.Forms Marquee iOS框架
- 6. 窗口邊框的寬度和高度
- 7. 定義邊框寬度(不是厚度)
- 8. CSS邊框寬度:1px不會給我同樣薄的邊框
- 9. 框架集邊框地獄框架集
- 10. 百分比邊框的寬度
- 11. CSS:設置邊框寬度的一半
- 12. 更改邊框寬度由XAML中,`wpf`
- 13. 的Java:調整邊框的寬度
- 14. 嵌套iText PdfPTable的邊框寬度
- 15. 圓形邊框寬度百分比?
- 16. 帶邊框的ul百分比寬度
- 17. 邊框和填充寬度javascript
- 18. 「模擬」 上COLGROUP邊框寬度與IE7
- 19. 使UISwitch邊框寬度變小
- 20. 像素邊框和百分比寬度
- 21. Bootstrap - 盒子邊框塌陷寬度
- 22. Safari 9.1.3邊框寬度問題
- 23. 在懸停時更改邊框寬度
- 24. 動畫邊框控件的寬度
- 25. HTML行邊框全表寬度
- 26. 框架邊框顏色
- 27. ListViewItem邊框 - 精簡框架
- 28. 在塊元素中限制邊框寬度爲文本寬度
- 29. CSS框架的寬度爲972px?
- 30. 選擇寬度實體框架和LINQ
是否有一個具體的理由,爲什麼你不希望使用效果如何?設置Frame的邊框寬度的問題對他們來說變得相當微不足道。 – hankide
我以爲有沒有效果的方式,只有PCL。如果沒有這種方法,我會做'效果' –