Home > Blockchain >  Inline if statement in xaml view .net maui
Inline if statement in xaml view .net maui

Time:08-29

Hello I am doing a form in .net maui where I want to have certain elements not be visible when a input has a certain value.

I tried the following but it doesn't work and I am struggling to find any documentaion that mentions inline if statements in xaml.

                <Picker x:Name="pickerMajor"
                                    TextColor="Black"
                                    MinimumWidthRequest="900"
                                    ItemsSource="{Binding Major}"
                                    ItemDisplayBinding="{Binding SubjectCode}"
                                    SelectedItem="{Binding SelectedSubjectMajor}"
                                    IsVisible="StudentDetail.StudentType == "Diploma" ? false : true"

                                    />

CodePudding user response:

You can use Xaml.cs to handle it or you StringToBooleanConverter.

CodePudding user response:

What's the StudentDetail.StudentType in the xaml? A property of the custom control? If so, you can try to use the data trigger.

Or it's a property in your viewmodel, you can try to declare a bool variable in the viewmodel and bind the IsVisiable to the variable. And then set the get method such as:

get => return !StudentDetail.StudentType == "Diploma";
  • Related