MobileTabStrip.xaml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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:mobile="clr-namespace:InABox.Mobile;assembly=InABox.Mobile.Shared"
  5. x:Class="InABox.Mobile.MobileTabStrip"
  6. x:DataType="mobile:MobileTabStrip">
  7. <ContentView.Resources>
  8. <ResourceDictionary>
  9. <DataTemplate x:Key="VerticalTemplate" x:DataType="mobile:MobileTabStripItem">
  10. <Frame
  11. Grid.Column="{Binding Index}"
  12. HasShadow="False"
  13. Margin="0"
  14. Padding="5"
  15. BorderColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  16. BackgroundColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  17. CornerRadius="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='CornerRadius'}"
  18. IsClippedToBounds="True"
  19. VerticalOptions="Fill"
  20. HorizontalOptions="Fill">
  21. <Frame.GestureRecognizers>
  22. <TapGestureRecognizer Tapped="DoTap"/>
  23. </Frame.GestureRecognizers>
  24. <Frame.Triggers>
  25. <DataTrigger TargetType="Frame" Binding="{Binding Selected}" Value="True">
  26. <Setter Property="BackgroundColor" Value="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='SelectedBackground'}" />
  27. </DataTrigger>
  28. </Frame.Triggers>
  29. <Grid>
  30. <Grid.RowDefinitions>
  31. <RowDefinition Height="*"/>
  32. <RowDefinition Height="Auto"/>
  33. </Grid.RowDefinitions>
  34. <Image
  35. x:Name="_image"
  36. Source="{Binding Image}"
  37. Grid.Row="0"
  38. Aspect="AspectFit"
  39. BackgroundColor="Transparent"
  40. HeightRequest="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='ImageSize.Height'}"
  41. WidthRequest="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='ImageSize.Width'}">
  42. <Image.GestureRecognizers>
  43. <TapGestureRecognizer Tapped="DoTap"/>
  44. </Image.GestureRecognizers>
  45. </Image>
  46. <Label
  47. x:Name="_label"
  48. Text="{Binding Text}"
  49. Grid.Row="1"
  50. FontSize="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='FontSize'}"
  51. FontAttributes="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='FontAttributes'}"
  52. HorizontalTextAlignment="Center"
  53. VerticalTextAlignment="Center"
  54. BackgroundColor="Transparent"
  55. TextColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedForeground'}">
  56. <Label.GestureRecognizers>
  57. <TapGestureRecognizer Tapped="DoTap" />
  58. </Label.GestureRecognizers>
  59. <Label.Triggers>
  60. <DataTrigger TargetType="Label" Binding="{Binding Selected}" Value="True">
  61. <Setter Property="TextColor" Value="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='SelectedForeground'}" />
  62. </DataTrigger>
  63. </Label.Triggers>
  64. </Label>
  65. </Grid>
  66. </Frame>
  67. </DataTemplate>
  68. <DataTemplate x:Key="HorizontalTemplate" x:DataType="mobile:MobileTabStripItem">
  69. <Frame
  70. Grid.Column="{Binding Index}"
  71. HasShadow="False"
  72. Margin="0"
  73. Padding="5"
  74. BorderColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  75. BackgroundColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  76. CornerRadius="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='CornerRadius'}"
  77. IsClippedToBounds="True"
  78. VerticalOptions="Fill"
  79. HorizontalOptions="Fill">
  80. <Frame.GestureRecognizers>
  81. <TapGestureRecognizer Tapped="DoTap"/>
  82. </Frame.GestureRecognizers>
  83. <Frame.Triggers>
  84. <DataTrigger TargetType="Frame" Binding="{Binding Selected}" Value="True">
  85. <Setter Property="BackgroundColor" Value="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='SelectedBackground'}" />
  86. </DataTrigger>
  87. </Frame.Triggers>
  88. <Grid>
  89. <Grid.ColumnDefinitions>
  90. <ColumnDefinition Width="Auto"/>
  91. <ColumnDefinition Width="*"/>
  92. </Grid.ColumnDefinitions>
  93. <Image
  94. x:Name="_image"
  95. Source="{Binding Image}"
  96. Grid.Column="0"
  97. Aspect="AspectFit"
  98. BackgroundColor="Transparent"
  99. HeightRequest="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='ImageSize.Height'}"
  100. WidthRequest="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='ImageSize.Width'}">
  101. <Image.GestureRecognizers>
  102. <TapGestureRecognizer Tapped="DoTap"/>
  103. </Image.GestureRecognizers>
  104. </Image>
  105. <Label
  106. x:Name="_label"
  107. Text="{Binding Text}"
  108. Grid.Column="1"
  109. FontSize="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='FontSize'}"
  110. FontAttributes="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='FontAttributes'}"
  111. HorizontalTextAlignment="Center"
  112. VerticalTextAlignment="Center"
  113. BackgroundColor="Transparent"
  114. TextColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedForeground'}">
  115. <Label.GestureRecognizers>
  116. <TapGestureRecognizer Tapped="DoTap" />
  117. </Label.GestureRecognizers>
  118. <Label.Triggers>
  119. <DataTrigger TargetType="Label" Binding="{Binding Selected}" Value="True">
  120. <Setter Property="TextColor" Value="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='SelectedForeground'}" />
  121. </DataTrigger>
  122. </Label.Triggers>
  123. </Label>
  124. </Grid>
  125. </Frame>
  126. </DataTemplate>
  127. <DataTemplate x:Key="TextOnlyTemplate" x:DataType="mobile:MobileTabStripItem">
  128. <Frame
  129. Grid.Column="{Binding Index}"
  130. HasShadow="False"
  131. Margin="0"
  132. Padding="5"
  133. BorderColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  134. BackgroundColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  135. CornerRadius="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='CornerRadius'}"
  136. IsClippedToBounds="True"
  137. VerticalOptions="Fill"
  138. HorizontalOptions="Fill">
  139. <Frame.GestureRecognizers>
  140. <TapGestureRecognizer Tapped="DoTap"/>
  141. </Frame.GestureRecognizers>
  142. <Frame.Triggers>
  143. <DataTrigger TargetType="Frame" Binding="{Binding Selected}" Value="True">
  144. <Setter Property="BackgroundColor" Value="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='SelectedBackground'}" />
  145. </DataTrigger>
  146. </Frame.Triggers>
  147. <Label
  148. x:Name="_label"
  149. Text="{Binding Text}"
  150. FontSize="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='FontSize'}"
  151. FontAttributes="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='FontAttributes'}"
  152. HorizontalTextAlignment="Center"
  153. VerticalTextAlignment="Center"
  154. BackgroundColor="Transparent"
  155. TextColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedForeground'}">
  156. <Label.GestureRecognizers>
  157. <TapGestureRecognizer Tapped="DoTap" />
  158. </Label.GestureRecognizers>
  159. <Label.Triggers>
  160. <DataTrigger TargetType="Label" Binding="{Binding Selected}" Value="True">
  161. <Setter Property="TextColor" Value="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='SelectedForeground'}" />
  162. </DataTrigger>
  163. </Label.Triggers>
  164. </Label>
  165. </Frame>
  166. </DataTemplate>
  167. <DataTemplate x:Key="ImageOnlyTemplate" x:DataType="mobile:MobileTabStripItem">
  168. <Frame
  169. Grid.Column="{Binding Index}"
  170. HasShadow="False"
  171. Margin="0"
  172. Padding="5"
  173. BorderColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  174. BackgroundColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  175. CornerRadius="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='CornerRadius'}"
  176. IsClippedToBounds="True"
  177. VerticalOptions="Fill"
  178. HorizontalOptions="Fill">
  179. <Frame.GestureRecognizers>
  180. <TapGestureRecognizer Tapped="DoTap"/>
  181. </Frame.GestureRecognizers>
  182. <Frame.Triggers>
  183. <DataTrigger TargetType="Frame" Binding="{Binding Selected}" Value="True">
  184. <Setter Property="BackgroundColor" Value="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='SelectedBackground'}" />
  185. </DataTrigger>
  186. </Frame.Triggers>
  187. <Image
  188. x:Name="_image"
  189. Source="{Binding Image}"
  190. Aspect="AspectFit"
  191. BackgroundColor="Transparent"
  192. HeightRequest="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='ImageSize.Height'}"
  193. WidthRequest="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='ImageSize.Width'}">
  194. <Image.GestureRecognizers>
  195. <TapGestureRecognizer Tapped="DoTap"/>
  196. </Image.GestureRecognizers>
  197. </Image>
  198. </Frame>
  199. </DataTemplate>
  200. <mobile:MobileTabStripDataTemplateSelector
  201. x:Key="MobileTabStripDataTemplateSelector"
  202. x:Name="_mobileTabStripDataTemplateSelector"
  203. TextOnlyTemplate="{StaticResource TextOnlyTemplate}"
  204. ImageOnlyTemplate="{StaticResource ImageOnlyTemplate}"
  205. VerticalTemplate="{StaticResource VerticalTemplate}"
  206. HorizontalTemplate="{StaticResource HorizontalTemplate}"/>
  207. </ResourceDictionary>
  208. </ContentView.Resources>
  209. <ContentView.Content>
  210. <Frame
  211. HasShadow="False"
  212. Margin="0"
  213. BorderColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='BorderColor'}"
  214. BackgroundColor="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='UnselectedBackground'}"
  215. CornerRadius="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='CornerRadius'}"
  216. IsClippedToBounds="True">
  217. <Frame.Padding>
  218. <OnPlatform x:TypeArguments="Thickness">
  219. <OnPlatform.Platforms>
  220. <On Platform="iOS" Value="0" />
  221. <On Platform="Android" Value="1" />
  222. </OnPlatform.Platforms>
  223. </OnPlatform>
  224. </Frame.Padding>
  225. <Grid
  226. x:Name="_grid"
  227. ColumnSpacing="0"
  228. BindableLayout.ItemTemplateSelector="{StaticResource MobileTabStripDataTemplateSelector}">
  229. <!-- <BindableLayout.ItemTemplateSelector> -->
  230. <!-- <mobile:MobileTabStripDataTemplateSelector -->
  231. <!-- SelectedLayout="{Binding Source={RelativeSource AncestorType={x:Type mobile:MobileTabStrip}}, Path='ItemsLayout'}" -->
  232. <!-- TextOnlyTemplate="{StaticResource TextOnlyTemplate}" -->
  233. <!-- ImageOnlyTemplate="{StaticResource ImageOnlyTemplate}" -->
  234. <!-- VerticalTemplate="{StaticResource VerticalTemplate}" -->
  235. <!-- HorizontalTemplate="{StaticResource HorizontalTemplate}"/> -->
  236. <!-- </BindableLayout.ItemTemplateSelector> -->
  237. </Grid>
  238. </Frame>
  239. </ContentView.Content>
  240. </ContentView>