简体   繁体   English

xaml 视图中的内联 if 语句 .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.您好,我正在 .net maui 中做一个表格,当输入具有特定值时,我希望某些元素不可见。

I tried the following but it doesn't work and I am struggling to find any documentaion that mentions inline if statements in xaml.我尝试了以下方法,但它不起作用,我很难找到任何提到 xaml 中的内联 if 语句的文档。

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

                                    />

You can use Xaml.cs to handle it or you StringToBooleanConverter.您可以使用 Xaml.cs 来处理它,也可以使用 StringToBooleanConverter。

What's the StudentDetail.StudentType in the xaml? StudentDetail.StudentType中的 StudentDetail.StudentType 是什么? 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.或者它是您的视图模型中的一个属性,您可以尝试在视图模型中声明一个布尔变量并将 IsVisiable 绑定到该变量。 And then set the get method such as:然后设置get方法如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM