|
5 | 5 | using Plugin.MaterialDesignControls.Material3.Implementations; |
6 | 6 | using Plugin.MaterialDesignControls.Styles; |
7 | 7 | using Xamarin.Forms; |
| 8 | +using static System.Net.Mime.MediaTypeNames; |
8 | 9 |
|
9 | 10 | namespace Plugin.MaterialDesignControls.Material3 |
10 | 11 | { |
@@ -111,6 +112,15 @@ public string Text |
111 | 112 | set { SetValue(TextProperty, value); } |
112 | 113 | } |
113 | 114 |
|
| 115 | + public static readonly BindableProperty IsTextUnderlinedProperty = |
| 116 | + BindableProperty.Create(nameof(IsTextUnderlined), typeof(bool), typeof(MaterialButton), defaultValue: false); |
| 117 | + |
| 118 | + public bool IsTextUnderlined |
| 119 | + { |
| 120 | + get { return (bool)GetValue(IsTextUnderlinedProperty); } |
| 121 | + set { SetValue(IsTextUnderlinedProperty, value); } |
| 122 | + } |
| 123 | + |
114 | 124 | public static readonly BindableProperty CornerRadiusProperty = |
115 | 125 | BindableProperty.Create(nameof(CornerRadius), typeof(double), typeof(MaterialButton), defaultValue: 20.0); |
116 | 126 |
|
@@ -386,7 +396,8 @@ private void Initialize() |
386 | 396 | HorizontalOptions = ContentIsExpanded ? LayoutOptions.CenterAndExpand : LayoutOptions.Center, |
387 | 397 | Text = ToUpper ? Text?.ToUpper() : Text, |
388 | 398 | FontSize = FontSize, |
389 | | - FontFamily = FontFamily |
| 399 | + FontFamily = FontFamily, |
| 400 | + TextDecorations = IsTextUnderlined ? TextDecorations.Underline : TextDecorations.None |
390 | 401 | }; |
391 | 402 | _stcLayout.Children.Add(_textLabel); |
392 | 403 |
|
@@ -428,6 +439,7 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName |
428 | 439 | case nameof(TextColor): |
429 | 440 | case nameof(BackgroundColor): |
430 | 441 | case nameof(BorderColor): |
| 442 | + case nameof(IsTextUnderlined): |
431 | 443 | SetButtonType(); |
432 | 444 | break; |
433 | 445 | case nameof(base.Opacity): |
@@ -570,31 +582,36 @@ public void SetButtonType() |
570 | 582 | { |
571 | 583 | case MaterialButtonType.Elevated: |
572 | 584 | _textLabel.TextColor = IsEnabled ? (TextColor != Color.Default ? TextColor : MaterialColor.Primary) : (DisabledTextColor != Color.Default ? DisabledTextColor : MaterialColor.Disable); |
| 585 | + _textLabel.TextDecorations = TextDecorations.None; |
573 | 586 | _frameLayout.BackgroundColor = BackgroundColor != Color.Default ? BackgroundColor : MaterialColor.OnPrimary; |
574 | 587 | _frameLayout.BorderColor = BackgroundColor != Color.Default ? BackgroundColor : MaterialColor.OnPrimary; |
575 | 588 | _frameLayout.HasShadow = true; |
576 | 589 | break; |
577 | 590 | case MaterialButtonType.Filled: |
578 | 591 | _textLabel.TextColor = IsEnabled ? (TextColor != Color.Default ? TextColor : MaterialColor.OnPrimary) : (DisabledTextColor != Color.Default ? DisabledTextColor : MaterialColor.OnPrimary); |
| 592 | + _textLabel.TextDecorations = TextDecorations.None; |
579 | 593 | _frameLayout.BackgroundColor = IsEnabled ? (BackgroundColor != Color.Default ? BackgroundColor : MaterialColor.Primary) : (DisabledBackgroundColor != Color.Default ? DisabledBackgroundColor : MaterialColor.Disable); |
580 | 594 | _frameLayout.BorderColor = Color.Transparent; |
581 | 595 | _frameLayout.HasShadow = false; |
582 | 596 | break; |
583 | 597 | case MaterialButtonType.Tonal: |
584 | 598 | _textLabel.TextColor = IsEnabled ? (TextColor != Color.Default ? TextColor : MaterialColor.Primary) : (DisabledTextColor != Color.Default ? DisabledTextColor : MaterialColor.Disable); |
| 599 | + _textLabel.TextDecorations = TextDecorations.None; |
585 | 600 | var defaultBackgroundColor = Color.FromRgba(MaterialColor.Primary.R, MaterialColor.Primary.G, MaterialColor.Primary.B, 0.4); |
586 | 601 | _frameLayout.BackgroundColor = IsEnabled ? defaultBackgroundColor : (DisabledBackgroundColor != Color.Default ? DisabledBackgroundColor : MaterialColor.Disable); |
587 | 602 | _frameLayout.BorderColor = Color.Transparent; |
588 | 603 | _frameLayout.HasShadow = false; |
589 | 604 | break; |
590 | 605 | case MaterialButtonType.Outlined: |
591 | 606 | _textLabel.TextColor = IsEnabled ? (TextColor != Color.Default ? TextColor : MaterialColor.Primary) : (DisabledTextColor != Color.Default ? DisabledTextColor : MaterialColor.Disable); |
| 607 | + _textLabel.TextDecorations = TextDecorations.None; |
592 | 608 | _frameLayout.BackgroundColor = BackgroundColor != Color.Default ? BackgroundColor : MaterialColor.OnPrimary; |
593 | 609 | _frameLayout.BorderColor = IsEnabled ? (BorderColor != Color.Default ? BorderColor : MaterialColor.Primary) : (DisabledBorderColor != Color.Default ? DisabledBorderColor : MaterialColor.Disable); |
594 | 610 | _frameLayout.HasShadow = false; |
595 | 611 | break; |
596 | 612 | case MaterialButtonType.Text: |
597 | 613 | _textLabel.TextColor = IsEnabled ? (TextColor != Color.Default ? TextColor : MaterialColor.Primary) : (DisabledTextColor != Color.Default ? DisabledTextColor : MaterialColor.Disable); |
| 614 | + _textLabel.TextDecorations = IsTextUnderlined ? TextDecorations.Underline : TextDecorations.None; |
598 | 615 | _frameLayout.BackgroundColor = Color.Transparent; |
599 | 616 | _frameLayout.BorderColor = Color.Transparent; |
600 | 617 | _frameLayout.HasShadow = false; |
|
0 commit comments