Search code examples
c#xaml.net-maui

Inline if statement in xaml view .net maui


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"

                                    />


Solution

  • 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";