.NET MAUI FAQ - Controls

Find answers for the most frequently asked questions
Expand All Collapse All

MenuFlyoutItem and MenuFlyoutSubItem inherit the IconImageSource property from Menu Item, which enables a small icon to be displayed next to the text for a context menu item. This icon can be an image or a font.

XAML

<Button  Text="&#x25B6;&#xFE0F;Play"
         WidthRequest="80"
         HeightRequest="50">
        <FlyoutBase.ContextFlyout>
            <MenuFlyout>
                <MenuFlyoutItem Text="Pause"
                                Clicked="MenuFlyoutItem_Clicked">
                    <MenuFlyoutItem.IconImageSource>
                        <FontImageSource Glyph="&#x23F8;"
                                         FontFamily="Arial" />
                    </MenuFlyoutItem.IconImageSource>
                </MenuFlyoutItem>
                <MenuFlyoutItem Text="Stop"
                                Clicked="MenuFlyoutItem_Clicked">
                    <MenuFlyoutItem.IconImageSource>
                        <FontImageSource Glyph="&#x23F9;"
                                         FontFamily="Arial" />
                    </MenuFlyoutItem.IconImageSource>
                </MenuFlyoutItem>
            </MenuFlyout>
        </FlyoutBase.ContextFlyout>
</Button>
Permalink

You can create sub-menu items by following this code,
XAML:

<Label x:Name="label"
       Text="Right-click to choose color">
        <FlyoutBase.ContextFlyout >
            <MenuFlyout  >
                   <MenuFlyoutItem  Text="Black"                                 
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="Black" />
                <MenuFlyoutSubItem  Text="Light" >
                    <MenuFlyoutItem Text="Blue"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="LightBlue" />
                    <MenuFlyoutItem Text="Coral"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="LightCoral" />
                    <MenuFlyoutItem Text="Cyan"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="LightCyan" />
                </MenuFlyoutSubItem>
                <MenuFlyoutSubItem  Text="Dark">
                    <MenuFlyoutItem Text="Blue"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="DarkBlue" />
                    <MenuFlyoutItem Text="Cyan"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="DarkCyan" />
                    <MenuFlyoutItem Text="Magenta"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="DarkMagenta" />
                </MenuFlyoutSubItem>
            </MenuFlyout>
        </FlyoutBase.ContextFlyout>
    </Label>
Permalink

Yes, you can add animations to a ProgressBar in .NET MAUI to create custom visual effects.
XAML:

<StackLayout Padding="20">
        <ProgressBar x:Name="animatedProgressBar"                     
                     BackgroundColor="LightGray"
                     ProgressColor="Green"
                     Progress="0" />

             <Button Text="Start Animation"
                     Clicked="StartAnimation_Clicked" />
 </StackLayout>

C#

private async void Button_Clicked(object sender, EventArgs e) 
{
   await animatedProgressBar.ProgressTo(1.0, 2000, Easing.Linear);
}
Permalink

You can customize the appearance of a ProgressBar in XAML by modifying properties like BackgroundColor, ProgressColor, and HeightRequest.
XAML:

<StackLayout Padding="20">      
        <ProgressBar  Progress="0.6"
                      BackgroundColor="Red"  
                      ProgressColor="Green" 
                      HeightRequest="20"/>           

             <Label   Text="60%" 
                      HorizontalOptions="Center" 
                      VerticalOptions="Center" />
 </StackLayout>
Permalink

To handle the selection change event of a Picker in XAML:
XAML:

<Picker x:Name="myPicker" SelectedIndexChanged="OnSelectedIndexChanged" >
        <Picker.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>Mark</x:String>
                <x:String>Jack</x:String>
                <x:String>Annie</x:String>
            </x:Array>
        </Picker.ItemsSource>
</Picker>

C#

private void OnSelectedIndexChanged(object sender, EventArgs e) 
{
        var selectedValue = myPicker.SelectedItem.ToString();
}
Permalink

You can set the selected item in C# code-behind using the SelectedIndex property or the SelectedItem property:

public MainPage()
{
	InitializeComponent();
       var myPicker = new Picker();
       myPicker.ItemsSource = new List<string> {"Mark,Annie,Rose"};        
       Content = myPicker;
       myPicker.SelectedIndex = 2; 
       myPicker.SelectedItem = "Rose";    
}
Permalink

You can create a basic Picker in XAML like this:
XAML:

   <Picker x:Name="myPicker" >
        <Picker.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>Jack</x:String>
                <x:String>Annie</x:String>
                <x:String>Martin</x:String>
            </x:Array>
        </Picker.ItemsSource>
    </Picker>
Permalink

A custom alert pop-up can be created by defining a separate pop-up page or view that includes the message you want to display as well as an OK button for dismissal. Here’s a simple example:

XAML

<VerticalStackLayout VerticalOptions="Center">
        <Button Text="Navigate to DetailsPage"
                Clicked="Button_Clicked" />
</VerticalStackLayout>

C#

private async void Button_Clicked(object sender, EventArgs e)
    {
        await DisplayAlert("Navigation Alert", "Navigate to next page", "OK");
        await Navigation.PushAsync(new DetailsPage());
    }
Permalink

.NET MAUI’s ListView does not have a built-in orientation property to switch between horizontal and vertical layouts. In .NET MAUI, the ListView typically displays items vertically. If you want to create a horizontal layout, you need to use a different layout container or a custom control.

XAML

<CollectionView ItemsSource="{Binding MyItems}">
     <CollectionView.ItemsLayout>
         <LinearItemsLayout Orientation="Horizontal" />
     </CollectionView.ItemsLayout>
     <!-- ItemTemplate and other customizations here -->
 </CollectionView>
Permalink

To add headers and footers to a ListView use  the `Header` and `Footer` properties.

XAML

<ListView ItemsSource="{Binding MyItems}">
    <!-- Header -->
    <ListView.Header>
        <Label Text="ListView Header" FontSize="20" TextColor="Blue" />
    </ListView.Header>
    <!-- Footer -->
    <ListView.Footer>
        <Label Text="ListView Footer" FontSize="20" TextColor="Green" />
    </ListView.Footer>
    <ListView.ItemTemplate>
        <DataTemplate>
            <!-- Customize the appearance of each ListView item here -->
            <ViewCell>
                <StackLayout Padding="10">
                    <Label Text="{Binding}" FontSize="18" TextColor="Black" />
                    <Image Source="icon.png" HeightRequest="30" WidthRequest="30" />
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
Permalink

To customize the appearance of ListView items define  a DataTemplate, which allows you to specify the layout and appearance of each item.

XAML

<ListView ItemsSource="{Binding MyItems}">
      <ListView.ItemTemplate>
          <DataTemplate>
              <!-- Customize the appearance of each ListView item here -->
              <ViewCell>
                  <StackLayout Padding="10">
                      <Label Text="{Binding}" FontSize="18" TextColor="Black" />
                      <Image Source="icon.png" HeightRequest="30" WidthRequest="30"/>
                  </StackLayout>
              </ViewCell>
          </DataTemplate>
      </ListView.ItemTemplate>
  </ListView>
Permalink

You can create a ListView by adding the `<ListView>` element in your XAML file or by creating an instance of `ListView` in your C# code.

XAML

<ListView>
     <ListView.ItemsSource>
         <x:Array Type="{x:Type x:String}">
             <x:String>Item 1</x:String>
             <x:String>Item 2</x:String>
             <x:String>Item 3</x:String>
         </x:Array>
     </ListView.ItemsSource>
 </ListView>  

OR

C#

var listView = new ListView();
listView.ItemsSource = new string[] { "Item 1", "Item 2", "Item 3" };
Content = listView;
Permalink

To enable pull-to-refresh, set the ‘IsPullToRefreshEnabled’ property to ‘true’ and specify a ‘RefreshCommand’. Users can then pull down the list to initiate the refresh action.  

XAML

<ContentPage.BindingContext>
     <local:BookViewModel />
 </ContentPage.BindingContext>
 <StackLayout>
     <ListView ItemsSource="{Binding Books}"
       IsPullToRefreshEnabled="true"
       RefreshCommand="{Binding RefreshCommand}"
       IsRefreshing="{Binding IsRefreshing}">
         <ListView.ItemTemplate>
             <DataTemplate>
                 <TextCell Text="{Binding Title}" />
             </DataTemplate>
         </ListView.ItemTemplate>
     </ListView>
 </StackLayout>

C#-MVVM

namespace PullToRefreshDemo.ViewModels;
public class Book
 {
     public string Title{ get; set; }
 }
public class BookViewModel : INotifyPropertyChanged
{
    public ObservableCollection<Book> Books { get; set; }
    public ICommand RefreshCommand { get; private set; }
    private bool isRefreshing;
    public bool IsRefreshing
    {
        get { return isRefreshing; }
        set { isRefreshing = value; OnPropertyChanged("IsRefreshing"); }
    }
    public BookViewModel()
    {
        Books = new ObservableCollection<Book>
        {
            new Book { Title = "Book 1" },
            new Book { Title = "Book 2" },
            new Book { Title = "Book 3" }
        };
        RefreshCommand = new Command(async () => await RefreshData());
    }
    private async Task RefreshData()
    {
        await Task.Delay(2000);    // Refresh Delay
        // Add new data or update existing data
        Books.Clear();
        Books.Add(new Book { Title = "Book 4" });
        Books.Add(new Book { Title = "Book 5" });
        IsRefreshing = false;     // Reset the IsRefreshing property to indicate that the refresh is complete
    }
    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(string propertyName)
    { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName))}
}
Permalink

You can handle item selection by subscribing to the ListView’s ItemSelected event. When a user selects an item, the event is triggered, and the OnItemSelected event handler is called, which retrieves the selected item.

XAML

<ListView ItemsSource="{Binding Books}"
        ItemSelected="OnItemSelected">
     <ListView.ItemTemplate>
         <DataTemplate>
             <TextCell Text="{Binding Title}" Detail="{Binding Description}" />
         </DataTemplate>
     </ListView.ItemTemplate>
 </ListView>

C#

private void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
	if (e.SelectedItem == null)
	return;
	// Handle the selected item (e.SelectedItem) here
	var selectedBook = e.SelectedItem as Book;

	// Do something with the selected book, e.g., display details
    DisplayAlert("Selected Book", $"Title:{selectedBook.Title}\nDescription: {selectedBook.Description}", "OK");

    // Clear the selection
    ((ListView)sender).SelectedItem = null;
}
Permalink

To populate a ListView, set its ItemsSource property to a collection of items, typically a list or an ObservableCollection. Each item represents one of the list’s entries. You can customize the appearance of each item in the ListView by assigning the DataTemplate within the ItemTemplate.

XAML

<ListView ItemsSource="{Binding Books}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding Title}"
          Detail="{Binding Description}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
Permalink

A .NET MAUI ListView is a user interface control that allows you to display lists of data or items in a scroll format. It is  flexible  and can be used to display data in a list or grid.

Permalink

You can customize the tabbed pages by creating new styles in TabbedPage.Resources and define styles to the tabs.

XAML

<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:local="clr-namespace:MultiseletionSample"
            x:Class="MultiseletionSample.MainPage">
    
    <TabbedPage.Resources>
        <Style TargetType="local:NewPage1" x:Key="style">
            <Setter Property="BackgroundColor" Value="Blue" />
        </Style>
    </TabbedPage.Resources>
    <local:NewPage1 Title="New" Style="{StaticResource style}"/>
    <local:NewPage2 Title="New" Style="{StaticResource style}"/>
    <local:NewPage3 Title="New" Style="{StaticResource style}"/>
    
</TabbedPage>

Permalink

You can customize the appearance of tabs by defining a custom style for the TabbedPage like this:
XAML

<TabbedPage xmls="http://schemas.microsoft.com/dotnet/2021/maui"
            Xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
        <TabbedPage.Resources>
            <Style TargetType="TabbedPage">
                <!-- Your custom styles here -->
            </Style>
        </TabbedPage.Resources>
       <!-- Add tab pages here -->
</TabbedPage>
Permalink

To add tabs to a tab control, you can use the Children property to add instances of Page or ContentPage.
XAML

<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:local="clr-namespace:MultiseletionSample"
            x:Class="MultiseletionSample.MainPage">
    <TabbedPage.Children>
        <local:NewPage1 Title="NewPage1" />
        <local:NewPage2 Title="NewPage2" />
        <!-- Other tabs -->
    </TabbedPage.Children>
</TabbedPage>
Permalink

You can create a tab control in .NET MAUI using the element in your XAML markup or by creating a new instance of the TabbedPage class in your C# code behind.
XAML:

<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:local="clr-namespace: TabbedPageSample"
            x:Class="TabbedPageSample.MainPage">
    
    <local:NewPage1/>
    <local:NewPage2/>
    <local:Remoteloctiondata/>
    <local:NewPage3/>
</TabbedPage>
Permalink

You can disable a button by setting its IsEnabled property to false. This will gray out the button and prevent user interaction.
XAML:

<Button x:Name="button" IsEnabled="False"/>

Permalink

Yes, you can customize a button’s appearance using properties like Background, TextColor, BorderColor, and BorderWidth, and apply styles.

XAML

<Button x:Name="button"
        TextColor="Black"
        BackgroundColor="Red"
        BorderColor="Aqua"
        BorderWidth="4"/>
Permalink

You can handle the Button click event by subscribing to the Button’s Clicked event and providing a handler method.
XAML:

<Button x:Name="button" Text="Click Me" Clicked="button_Clicked"/>

C#

button.Clicked += button_Clicked;

private void MyButton_Clicked(object sender, EventArgs e)
{
    // Handle the button click here
}
Permalink

Buttons are interactive user interface elements that allow users to trigger actions or events when clicked or tapped. Buttons are used to create interactive and responsive user interfaces in mobile and desktop applications. In .NET MAUI, buttons are represented by the Button class.

Permalink

To create a navigation drawer in .NET MAUI, you can use the “Grid” that slides in from the left side of the screen when a button is clicked. This drawer will include various menu items for navigation.

XAML

<Grid>
    <!-- Content Area -->
    <Grid>
        <Label Text="Main Content" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
        <Button Text="=>" Clicked="OnOpenDrawerClicked" HorizontalOptions="Start" VerticalOptions="Start" />
    </Grid>
    <!-- Navigation Drawer -->
<Grid x:Name="navigationDrawer" BackgroundColor="LightGray" TranslationX="-300"     WidthRequest="300" VerticalOptions="FillAndExpand" HorizontalOptions="StartAndExpand" RowDefinitions="Auto,Auto,Auto,Auto" ColumnDefinitions="*,Auto" RowSpacing="20" >
        <Label Grid.Row="0" Text="NavigationDrawer" VerticalOptions="Center" HorizontalOptions="Center" />
        <Button Grid.Column="1" Text="X" Clicked="OnCloseDrawerClicked"/>
        <Label Grid.Row="1" Text="Menu Item 1" VerticalOptions="StartAndExpand" />
        <Label Grid.Row="2" Text="Menu Item 2" VerticalOptions="StartAndExpand" />
        <Label Grid.Row="3" Text="Menu Item 3" VerticalOptions="StartAndExpand" />
    </Grid>
</Grid>

C#

 async void OnOpenDrawerClicked(object sender, EventArgs e)
 {
     await navigationDrawer.TranslateTo(0, 0, 250);
 }
 async void OnCloseDrawerClicked(object sender, EventArgs e)
 {
     await navigationDrawer.TranslateTo(-300, 0, 250);
 }
Permalink

You can use the Image control as a background and overlay it with other controls like Label or BoxView to add text or other elements.

<Grid HeightRequest="200" WidthRequest="200">
    <Image Source="art.png" Aspect="AspectFill" />
    <StackLayout HorizontalOptions="Center"  BackgroundColor="#80000000" VerticalOptions="Center">
        <Label Text="Overlay Text" TextColor="White" FontAttributes="Bold" FontSize="24" />
    </StackLayout>
</Grid>
Permalink

To crop an image in .NET MAUI, use the Clip feature.

<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
    <Image Source="art.png" HeightRequest="200" WidthRequest="200" VerticalOptions="Start" HorizontalOptions="Start">
        <Image.Clip>
            <EllipseGeometry Center="100,100" RadiusX="100" RadiusY="100" />
        </Image.Clip>
    </Image>
</StackLayout>

Permalink

Animating a BoxView in .NET MAUI can be done using the framework’s built-in animation features. You can use the VisualElement’s TranslateTo, RotateTo, ScaleTo, and other animation methods to achieve various animation effects. Here is an example:

public partial class MainPage : ContentPage
 {
     public BoxView myBoxView;
     public MainPage()
     {
         InitializeComponent();

         myBoxView = new Microsoft.Maui.Controls.BoxView()
         {
             WidthRequest = 200,
             HeightRequest = 200,
             Color = Colors.Blue
         };
         var tapGesture = new TapGestureRecognizer();
         tapGesture.Tapped += OnBoxViewTapped;

         myBoxView.GestureRecognizers.Add(tapGesture);

         StackLayout views = new StackLayout()
         {
             Children = { myBoxView },
             VerticalOptions = LayoutOptions.Center,
             HorizontalOptions = LayoutOptions.Center
         };
         Content = views;
     }

     private async void OnBoxViewTapped(object sender, EventArgs e)
     {
         double finalWidth = 200;
         double finalHeight = 200;

         await myBoxView.ScaleTo(1.2, 250); 
         await Task.Delay(100); 
         await myBoxView.ScaleTo(0.8, 250); 
         await myBoxView.ScaleTo(1.0, 250); 
     }
 }
Permalink

In .NET MAUI, you can make a BoxView respond when a user drags or swipes it by using something called PanGestureRecognizer. Here’s an example:

myBoxView = new BoxView()
    {
        WidthRequest = 200,
        HeightRequest = 200,
        Color=Colors.Blue
    };
    var gestureRecognizer = new PanGestureRecognizer();
    gestureRecognizer.PanUpdated += (sender, e) =>
    {
        switch (e.StatusType)
        {
            case GestureStatus.Started:
                break;
            case GestureStatus.Running:
                double xOffset = myBoxView.TranslationX + e.TotalX;
                double yOffset = myBoxView.TranslationY + e.TotalY;
                myBoxView.TranslationX = xOffset;
                myBoxView.TranslationY = yOffset;
                break;
            case GestureStatus.Completed:
                break;
        }
    };

    myBoxView.GestureRecognizers.Add(gestureRecognizer);
    StackLayout views = new StackLayout()
    {
        Children = {myBoxView},
        VerticalOptions = LayoutOptions.CenterAndExpand,
        HorizontalOptions = LayoutOptions.CenterAndExpand
    };
    Content = views;
Permalink

In .NET MAUI, you can make a BoxView respond when a user taps on it by using something called a tap gesture. This lets you tell the BoxView what to do when someone taps it. Here is an example:

public partial class MainPage : ContentPage
 {
     public BoxView myBoxView;
     public MainPage()
     {
         InitializeComponent();

         myBoxView = new Microsoft.Maui.Controls.BoxView()
         {
             WidthRequest = 200,
             HeightRequest = 200,
             Color = Colors.Blue
         };

         // Create a TapGestureRecognizer
         var tapGesture = new TapGestureRecognizer();
         tapGesture.Tapped += OnBoxViewTapped;

         // Attach the TapGestureRecognizer to the BoxView
         myBoxView.GestureRecognizers.Add(tapGesture);

         StackLayout views = new StackLayout()
         {
             Children = { myBoxView }
         };
         Content = views;
     }

     private void OnBoxViewTapped(object sender, EventArgs e)
     {
         // Handle the tap gesture here
         myBoxView.Color = Colors.Red; // Change the color, for example
     }
 }
Permalink

Yes, you can conditionally enable or disable a command by implementing the CanExecute method. Here is an example:

bool CanSubmit = true; // Your condition or Boolean property
 Button myButton = new Button
 {
     Text = "Submit",
 };

 myButton.Command = new Command(() =>
 {
     DisplayAlert("Button Clicked", "Button was clicked!", "OK");
 }, () => CanSubmit);

 Content = new StackLayout
 {
     Children = { myButton },
     VerticalOptions = LayoutOptions.CenterAndExpand,
     HorizontalOptions = LayoutOptions.CenterAndExpand
 };
Permalink

.NET MAUI’s navigation commands let you push and pop pages from the navigation stack.

public partial class MainPage : ContentPage
 {
     public MainPage()
     {
         InitializeComponent();
         Title = "Main Page";
         var navigateButton = new Button
         {
             Text = "Navigate to Second Page",
             Command = new Command(() =>
             {
                 // Use Navigation to push the SecondPage onto the navigation stack
                 Navigation.PushAsync(new SecondPage());
             })
         };

         Content = new StackLayout
         {
             Children = { navigateButton },
             VerticalOptions = LayoutOptions.CenterAndExpand,
             HorizontalOptions = LayoutOptions.CenterAndExpand
         };
	}
}
public class SecondPage : ContentPage
{
    public SecondPage()
    {
        Title = "Second Page";
        var backButton = new Button
        {
            Text = "Go Back",
            Command = new Command(() =>
            {
                // Use Navigation to pop the current page (SecondPage) from the navigation stack
                Navigation.PopAsync();
            })
        };

        Content = new StackLayout
        {
            Children = { backButton },
            VerticalOptions = LayoutOptions.CenterAndExpand,
            HorizontalOptions = LayoutOptions.CenterAndExpand
        };
    }
}
Permalink

Yes, you can transmit parameters to a command by using the CommandParameter property. Here is an example involving a parameter:

C#

Button myButton = new Button
 {
     Text = "Click Me",
     Command = new Command((parameter) =>
     {
         string parameterValue = parameter as string;

         if (!string.IsNullOrEmpty(parameterValue))
         {
             DisplayAlert(parameterValue, "Button was clicked!", "OK");
         }
     }),
     CommandParameter = "Hello, .NET MAUI!"
 };

 var stackLayout = new StackLayout
 {
     Children = { myButton }
 };
 Content = stackLayout;
Permalink

Utilizing commands to execute actions in response to user interactions involves associating them with UI elements, as demonstrated in the following example with a button:

C#

Button myButton = new Button
 {
     Text = "Click Me",
     Command = new Command(() =>
     {
         DisplayAlert("Button Clicked", "Button was clicked!", "OK");
     })
 };
 var stackLayout = new StackLayout
 {
     Children = { myButton }
 };
 Content = stackLayout;
Permalink

To create a custom type converter, you need to implement the IValueConverter class and override the Convert and ConvertBack methods. Here’s an example in XAML:

XAML

<ContentPage.Resources>
	<local:IntToBoolConverter x:Key="intToBool" />
</ContentPage.Resources>

    <StackLayout Padding="10, 0">
        <Entry  x:Name="entry1"
                Text=""
                Placeholder="enter search term"
                VerticalOptions="Center" />
        <Button Text="Search"
                HorizontalOptions="Center"
                VerticalOptions="Center"
                IsEnabled="{Binding Source={x:Reference entry1},
                Path=Text.Length,
                Converter={StaticResource intToBool}}" />        
    </StackLayout>

C#

public class IntToBoolConverter : IValueConverter 
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
	{
		return (int)value != 0;
	}

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
	{
		return (bool)value ? 1 : 0;
	}
}
Permalink

Share with

Couldn't find the FAQs you're looking for?

Please submit your question and answer.