MobileButton.xaml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. <local:MobileCard
  15. x:Name="_frame"
  16. IsEnabled="True"
  17. BackgroundColor="{TemplateBinding BackgroundColor}"
  18. BorderColor="{TemplateBinding BorderColor}"
  19. Clicked="_frame_OnClicked">
  20. <local:MobileCard.Triggers>
  21. <DataTrigger TargetType="local:MobileCard" Binding="{TemplateBinding IsEnabled}" Value="False">
  22. <Setter Property="BackgroundColor" Value="Silver" />
  23. </DataTrigger>
  24. <DataTrigger TargetType="local:MobileCard" Binding="{TemplateBinding IsEnabled}" Value="False">
  25. <Setter Property="BorderColor" Value="Gray" />
  26. </DataTrigger>
  27. </local:MobileCard.Triggers>
  28. <Grid>
  29. <Grid
  30. Grid.Row="0"
  31. Grid.Column="0"
  32. Padding = "{TemplateBinding Padding}">
  33. <StackLayout
  34. x:Name="_layout"
  35. Grid.Row="0"
  36. Grid.Column="0"
  37. Orientation="{TemplateBinding Orientation}"
  38. HorizontalOptions = "CenterAndExpand"
  39. VerticalOptions = "CenterAndExpand">
  40. <Image
  41. x:Name="_image"
  42. Source="{TemplateBinding Image}"
  43. IsVisible="{TemplateBinding Image, Converter={StaticResource ImageSourceToBooleanConverter}}"
  44. WidthRequest="24"
  45. HeightRequest="24"
  46. Aspect="AspectFit"
  47. />
  48. <material:MaterialLabel
  49. x:Name="_label"
  50. Text="{TemplateBinding Text, Converter={StaticResource MobileButtonTextFormatter}}"
  51. VerticalOptions="CenterAndExpand"
  52. HorizontalOptions="FillAndExpand"
  53. TypeScale = "{TemplateBinding TypeScale}"
  54. HorizontalTextAlignment = "Center"
  55. TextColor="{TemplateBinding TextColor}"
  56. IsVisible="{TemplateBinding Text, Converter={StaticResource StringToBooleanConverter}}"
  57. >
  58. <material:MaterialLabel.Triggers>
  59. <DataTrigger TargetType="material:MaterialLabel" Binding="{TemplateBinding IsEnabled}" Value="False">
  60. <Setter Property="TextColor" Value="Gray" />
  61. </DataTrigger>
  62. </material:MaterialLabel.Triggers>
  63. </material:MaterialLabel>
  64. </StackLayout>
  65. </Grid>
  66. <Frame
  67. Grid.Row="0"
  68. Grid.Column="0"
  69. HorizontalOptions="End"
  70. VerticalOptions="Start"
  71. HeightRequest="20"
  72. WidthRequest="20"
  73. CornerRadius="15"
  74. IsVisible="{TemplateBinding Alert, Converter={StaticResource StringToBooleanConverter}}"
  75. HasShadow="False"
  76. Margin="0,2,2,0"
  77. BackgroundColor="Yellow" Padding="1">
  78. <Label
  79. FontAttributes="Bold"
  80. TextColor="Red"
  81. FontSize="Micro"
  82. HorizontalOptions="Center"
  83. VerticalOptions="Center"
  84. Text="{TemplateBinding Alert}"/>
  85. </Frame>
  86. </Grid>
  87. </local:MobileCard>
  88. </ControlTemplate>
  89. </ContentView.ControlTemplate>
  90. </ContentView>