MobileButton.xaml 5.5 KB

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