2017-10-30 17 views
5

मैं Xamarin फॉर्म साझा प्रोजेक्ट पर फ़्रेम नियंत्रण का उपयोग कर रहा हूं।फ़्रेम सेट करना। बैकग्राउंडकॉलर Xamarin रूपों पर गोलाकार कोने खो देता है

<Color x:Key="Info">#0060ac</Color> 
... 
<Style x:Key="LabelContainer" TargetType="Frame"> 
    <Setter Property="Padding" Value="5" /> 
    <Setter Property="HorizontalOptions" Value="Fill" /> 
</Style> 
<Style x:Key="LabelContainer-Info" TargetType="Frame" BasedOn="{StaticResource LabelContainer}"> 
    <Setter Property="BackgroundColor" Value="{DynamicResource Info}" /> 
</Style> 

और XAML पेज में एक सरल फ्रेम नियंत्रण: मैं बस कुछ शैलियों है

 <Frame x:Name="CreditCardPaymentResultFrame" Style="{StaticResource LabelContainer-Info}" Padding="0"> 
      <Label x:Name="PaymentErrorLabel" Text="Lorem ipsum" IsVisible="True" 
        HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" 
        VerticalTextAlignment="Center" HorizontalTextAlignment="Center" 
        FontSize="18" TextColor="White"> 
      </Label> 
     </Frame> 

और मैं इस तरह somthing मिलती है:

enter image description here

अब, अगर मैं रन टाइम पर पृष्ठभूमि रंग बदलने की कोशिश करें:

CreditCardPaymentResultFrame.BackgroundColor = Color.FromHex("#ed3700"); 

फ्रेम नियंत्रण सीमा गोलाई खो देता है:

enter image description here

मैं इस व्यवहार को समझने के नहीं है, मैं वापस रंग बदलने की जरूरत है, लेकिन मैं गोल किनारों रखने के लिए करना चाहते हैं।

जो कोई मुझे हाथ

+0

आप क्या मंच का उपयोग करते हैं? –

+0

हाय। मैं एंड्रॉइड का उपयोग कर रहा हूँ –

उत्तर

1

एंड्रॉयड पर समान मुद्दे के साथ सामना है, लेकिन सीमा के रंग से संबंधित दे दी के लिए धन्यवाद। इसे ठीक करने के लिए, मैं एक नया नियंत्रण बनाया, Frame से विरासत में मिला है और इसके लिए एक रेंडरर लागू किया, लेकिन VisualElementRenderer<Frame>FrameRenderer के बजाय एक आधार वर्ग के रूप में इस्तेमाल:

[assembly: ExportRenderer(typeof(MyFrame), typeof(MyFrameRenderer))] 
namespace Android.Renderers 
{ 
    public class MyFrameRenderer : VisualElementRenderer<Frame> 
    { 
    protected override void OnElementChanged(ElementChangedEventArgs<Frame> e) 
    { 
     base.OnElementChanged(e); 

     if (e.NewElement != null) 
     { 
      var drawable = new GradientDrawable(); 
      ViewGroup.SetBackground(drawable); 
      UpdateBackgroundColor(drawable); 
      UpdateCornerRadius(drawable); 
      UpdateOutlineColor(drawable); 
      UpdateShadow(); 
     } 
    } 

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) 
    { 
     base.OnElementPropertyChanged(sender, e); 

     var drawable = ViewGroup?.Background as GradientDrawable; 
     if (drawable != null) 
     { 
      if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) 
      { 
       UpdateBackgroundColor(drawable); 
      } 
      else if (e.PropertyName == Frame.CornerRadiusProperty.PropertyName) 
      { 
       UpdateCornerRadius(drawable); 
      } 
      else if (e.PropertyName == Frame.OutlineColorProperty.PropertyName) 
      { 
       UpdateOutlineColor(drawable); 
      } 
      else if (e.PropertyName == Frame.HasShadowProperty.PropertyName) 
      { 
       UpdateShadow(); 
      } 
     } 
    } 

    protected override void UpdateBackgroundColor() 
    { 
     // This method doesn't work well in Xamarin.Forms -Version 2.3.4.247 
    } 

    private void UpdateCornerRadius(GradientDrawable drawable) 
    { 
     drawable.SetCornerRadius(Element.CornerRadius); 
    } 

    private void UpdateOutlineColor(GradientDrawable drawable) 
    { 
     drawable.SetStroke(1, Element.OutlineColor.ToAndroid()); 
    } 

    private void UpdateBackgroundColor(GradientDrawable drawable) 
    { 
     drawable.SetColor(Element.BackgroundColor.ToAndroid()); 
    } 

    private void UpdateShadow() 
    { 
     if (Element.HasShadow) 
     { 
      Elevation = (float)Context.FromPixels(10); 
     } 
     else 
     { 
      Elevation = 0; 
     } 
    } 
    } 
} 
संबंधित मुद्दे