gpt4 book ai didi

c# - 如何在 Xamarin.Forms 的选取器中显示 ItemDisplayBinding 中的默认枚举值

转载 作者:行者123 更新时间:2023-11-30 22:58:19 27 4
gpt4 key购买 nike

查看:

<Picker ItemsSource="{Binding ECCLevels}" 
ItemDisplayBinding="{Binding QRCodeGenerator.ECCLevel}"
HeightRequest="44"/>

View 模型:

public ObservableCollection<QRCodeGenerator.ECCLevel> ECCLevels { get; set; } = new ObservableCollection<QRCodeGenerator.ECCLevel>();

ECCLevels = new ObservableCollection<QRCodeGenerator.ECCLevel>(Enum.GetValues(typeof(QRCodeGenerator.ECCLevel)).OfType<QRCodeGenerator.ECCLevel>().ToList());

我简化了上面的代码。 ObservableCollection 在第二行代码之后被数据填充。但问题是我不知道在选择器的 ItemDisplayBinding 属性中放入什么,因为 Enum 直接转换为列表而不通过模型。

最佳答案

您可以只使用ItemDisplayBinding="{Binding .}",点符号表示您基本上指的是this。因此,通过这种方式,您只需引用对象本身,而不是任何其他属性。

在评论中你问我我是怎么知道的,这实际上是我很好的问题。我想我早在 WPF 就开始使用它了。但是很难从文档中挖掘出来,我在这里找到了一个小通知:https://learn.microsoft.com/en-us/dotnet/api/system.windows.data.binding.path?redirectedfrom=MSDN&view=netframework-4.7.2#System_Windows_Data_Binding_Path

Optionally, a period (.) path can be used to bind to the current source. For example, Text="{Binding}" is equivalent to Text="{Binding Path=.}".

关于c# - 如何在 Xamarin.Forms 的选取器中显示 ItemDisplayBinding 中的默认枚举值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53078446/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com