-
Notifications
You must be signed in to change notification settings - Fork 340
/
EnumToIntConverterPage.xaml
25 lines (25 loc) · 1.88 KB
/
EnumToIntConverterPage.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
<?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"
xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Converters"
x:Class="CommunityToolkit.Maui.Sample.Pages.Converters.EnumToIntConverterPage"
x:DataType="vm:EnumToIntConverterViewModel"
x:TypeArguments="vm:EnumToIntConverterViewModel">
<pages:BasePage.Resources>
<ResourceDictionary>
<mct:EnumToIntConverter x:Key="EnumToIntConverter" />
</ResourceDictionary>
</pages:BasePage.Resources>
<pages:BasePage.Content>
<VerticalStackLayout Padding="10,10" Spacing="10">
<Label Text="The EnumToIntConverter is a converter that allows users to convert a standard enum (extending int) to its underlying primitive int type." TextColor="{StaticResource NormalLabelTextColor}" />
<Label Text="Selecting a value from the picker will change the enum property in the view model" TextColor="{StaticResource NormalLabelTextColor}" />
<Picker ItemsSource="{Binding AllStates}" SelectedIndex="{Binding SelectedState, Converter={StaticResource EnumToIntConverter}, ConverterParameter={x:Type vm:IssueState}}" TextColor="{StaticResource NormalLabelTextColor}" />
<Label Text="This label binds to the SelectedIndex property of the picker, both use EnumToIntConverter, so no int properties are necessary in ViewModel" TextColor="{StaticResource NormalLabelTextColor}" />
<Label Text="{Binding Path=SelectedState, Converter={StaticResource EnumToIntConverter}}" TextColor="{StaticResource NormalLabelTextColor}" />
</VerticalStackLayout>
</pages:BasePage.Content>
</pages:BasePage>