-
Notifications
You must be signed in to change notification settings - Fork 338
/
EnumToBoolConverterPage.xaml
47 lines (43 loc) · 2.69 KB
/
EnumToBoolConverterPage.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?xml version="1.0" encoding="utf-8" ?>
<pages:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
x:Class="CommunityToolkit.Maui.Sample.Pages.Converters.EnumToBoolConverterPage"
xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Converters"
x:TypeArguments="vm:EnumToBoolConverterViewModel"
x:DataType="vm:EnumToBoolConverterViewModel">
<pages:BasePage.Resources>
<ResourceDictionary>
<!-- Converter with TRUE list -->
<mct:EnumToBoolConverter x:Key="MobileConverter">
<mct:EnumToBoolConverter.TrueValues>
<vm:MyDevicePlatform>Android</vm:MyDevicePlatform>
<vm:MyDevicePlatform>iOS</vm:MyDevicePlatform>
</mct:EnumToBoolConverter.TrueValues>
</mct:EnumToBoolConverter>
<mct:EnumToBoolConverter x:Key="DesktopConverter">
<mct:EnumToBoolConverter.TrueValues>
<vm:MyDevicePlatform>MacCatalyst</vm:MyDevicePlatform>
<vm:MyDevicePlatform>WinUI</vm:MyDevicePlatform>
</mct:EnumToBoolConverter.TrueValues>
</mct:EnumToBoolConverter>
<!-- Converter, that uses parameter -->
<mct:EnumToBoolConverter x:Key="PlatformConverter" />
</ResourceDictionary>
</pages:BasePage.Resources>
<pages:BasePage.Content>
<VerticalStackLayout Spacing="12">
<Label Text="EnumToBoolConverter converts an Enum to corresponding boolean value."
HorizontalOptions="CenterAndExpand" />
<Label Text="👇 Change the Picker value to see the below Label Text change."/>
<Picker ItemsSource="{Binding Platforms}" SelectedItem="{Binding SelectedPlatform}" />
<!-- Converter with TRUE list -->
<Label IsVisible="{Binding SelectedPlatform, Converter={StaticResource MobileConverter}}" Text="This text is visible when the Picker value is Android or iOS."/>
<Label IsVisible="{Binding SelectedPlatform, Converter={StaticResource DesktopConverter}}" Text="This text is visible when the Picker value is MacCatalyst or WinUI."/>
<!-- Converter, that uses parameter -->
<Label IsVisible="{Binding SelectedPlatform, Converter={StaticResource PlatformConverter}, ConverterParameter={x:Static vm:MyDevicePlatform.Tizen}}" Text="This text is visible when the Picker value is Platform is Tizen."/>
</VerticalStackLayout>
</pages:BasePage.Content>
</pages:BasePage>