MobileButton.xaml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  4. xmlns:material="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material"
  5. xmlns:local="clr-namespace:InABox.Mobile"
  6. x:Class="InABox.Mobile.MobileButton">
  7. <ContentView.Resources>
  8. <local:StringToBooleanConverter x:Key="StringToBooleanConverter"/>
  9. <local:ImageSourceToBooleanConverter x:Key="ImageSourceToBooleanConverter"/>
  10. <local:MobileButtonTextFormatter x:Key="MobileButtonTextFormatter" x:Name="_textformatter"/>
  11. </ContentView.Resources>
  12. <ContentView.ControlTemplate>
  13. <ControlTemplate>
  14. <material:MaterialCard
  15. x:Name="_frame"
  16. CornerRadius = "5"
  17. Elevation = "0"
  18. Margin = "0"
  19. HasShadow = "False"
  20. Padding="0"
  21. IsClickable = "True"
  22. IsEnabled="True"
  23. BackgroundColor="{TemplateBinding BackgroundColor}"
  24. BorderColor="{TemplateBinding BorderColor}"
  25. Clicked="_frame_OnClicked">
  26. <material:MaterialCard.Triggers>
  27. <!-- <DataTrigger TargetType="material:MaterialCard" Binding="{TemplateBinding IsEnabled}" Value="True"> -->
  28. <!-- <Setter Property="BackgroundColor" Value="{TemplateBinding ButtonColor}" /> -->
  29. <!-- </DataTrigger> -->
  30. <DataTrigger TargetType="material:MaterialCard" Binding="{TemplateBinding IsEnabled}" Value="False">
  31. <Setter Property="BackgroundColor" Value="Silver" />
  32. </DataTrigger>
  33. <!-- <DataTrigger TargetType="material:MaterialCard" Binding="{TemplateBinding IsEnabled}" Value="True"> -->
  34. <!-- <Setter Property="BorderColor" Value="{TemplateBinding BorderColor}" /> -->
  35. <!-- </DataTrigger> -->
  36. <DataTrigger TargetType="material:MaterialCard" Binding="{TemplateBinding IsEnabled}" Value="False">
  37. <Setter Property="BorderColor" Value="Gray" />
  38. </DataTrigger>
  39. </material:MaterialCard.Triggers>
  40. <Grid>
  41. <Grid
  42. Grid.Row="0"
  43. Grid.Column="0"
  44. Padding = "{TemplateBinding Padding}">
  45. <StackLayout
  46. x:Name="_layout"
  47. Grid.Row="0"
  48. Grid.Column="0"
  49. Orientation="{TemplateBinding Orientation}"
  50. HorizontalOptions = "CenterAndExpand"
  51. VerticalOptions = "CenterAndExpand">
  52. <Image
  53. x:Name="_image"
  54. Source="{TemplateBinding Image}"
  55. IsVisible="{TemplateBinding Image, Converter={StaticResource ImageSourceToBooleanConverter}}"
  56. WidthRequest="24"
  57. HeightRequest="24"
  58. Aspect="AspectFit"
  59. />
  60. <material:MaterialLabel
  61. x:Name="_label"
  62. Text="{TemplateBinding Text, Converter={StaticResource MobileButtonTextFormatter}}"
  63. VerticalOptions="CenterAndExpand"
  64. HorizontalOptions="FillAndExpand"
  65. TypeScale = "{TemplateBinding TypeScale}"
  66. HorizontalTextAlignment = "Center"
  67. TextColor="{TemplateBinding TextColor}"
  68. IsVisible="{TemplateBinding Text, Converter={StaticResource StringToBooleanConverter}}"
  69. >
  70. <material:MaterialLabel.Triggers>
  71. <DataTrigger TargetType="material:MaterialLabel" Binding="{TemplateBinding IsEnabled}" Value="False">
  72. <Setter Property="TextColor" Value="Gray" />
  73. </DataTrigger>
  74. </material:MaterialLabel.Triggers>
  75. </material:MaterialLabel>
  76. </StackLayout>
  77. </Grid>
  78. <Frame
  79. Grid.Row="0"
  80. Grid.Column="0"
  81. HorizontalOptions="End"
  82. VerticalOptions="Start"
  83. HeightRequest="20"
  84. WidthRequest="20"
  85. CornerRadius="15"
  86. IsVisible="{TemplateBinding Alert, Converter={StaticResource StringToBooleanConverter}}"
  87. HasShadow="False"
  88. Margin="0,2,2,0"
  89. BackgroundColor="Yellow" Padding="1">
  90. <Label
  91. FontAttributes="Bold"
  92. TextColor="Red"
  93. FontSize="Micro"
  94. HorizontalOptions="Center"
  95. VerticalOptions="Center"
  96. Text="{TemplateBinding Alert}"/>
  97. </Frame>
  98. </Grid>
  99. </material:MaterialCard>
  100. </ControlTemplate>
  101. </ContentView.ControlTemplate>
  102. </ContentView>