gpt4 book ai didi

xamarin - ItemsSource 可绑定(bind)属性

转载 作者:行者123 更新时间:2023-12-05 06:36:04 25 4
gpt4 key购买 nike

我正在尝试使用 2 个项目(LabelDatePicker)制作 ContentView,我需要发送 ItemsSource 作为可绑定(bind)属性的第二项。

我尝试使用 BindingBase,但没有成功。

Xaml:

<Grid>
<Label
Text="Text"
TextColor="Black"
VerticalOptions="CenterAndExpand" />

<controls:ExtendedPicker
Title="Title"
HorizontalOptions="End"
ItemDisplayBinding="{Binding PickerItemDisplayBinding, Source={x:Reference This}}"
ItemsSource="{Binding PickerItemsSource, Source={x:Reference This}}"
SelectedIndex="{Binding PickerSelectedIndex, Source={x:Reference This}}" />
</Grid>

Xaml.cs:

public static readonly BindableProperty PickerItemsSourceProperty = BindableProperty.Create(
"PickerItemsSource",
typeof(IList),
typeof(DetailedPicker));

public static readonly BindableProperty PickerSelectedIndexProperty = BindableProperty.Create(
"PickerSelectedIndex",
typeof(int),
typeof(DetailedPicker));

public static readonly BindableProperty PickerItemDisplayBindingProperty = BindableProperty.Create(
"PickerItemDisplayBinding",
typeof(BindingBase),
typeof(DetailedPicker));


public IList PickerItemsSource
{
get => (IList) GetValue(PickerItemsSourceProperty);
set => SetValue(PickerItemsSourceProperty, value);
}

public int PickerSelectedIndex
{
get => (int) GetValue(PickerSelectedIndexProperty);
set => SetValue(PickerSelectedIndexProperty, value);
}

public BindingBase PickerItemDisplayBinding
{
get => (BindingBase) GetValue(PickerItemDisplayBindingProperty);
set => SetValue(PickerItemDisplayBindingProperty, value);
}

如何将 ItemsSource 绑定(bind)为 ContentViewBindableProperty

最佳答案

我不确定您是否可以对 this 关键字使用 x:Reference。我从来没有听说过这样的事情。

虽然我想您可以解决这个问题,方法是为您的 ContentView 提供一个 x:Name。就像这样:

<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Your.Controls.Namespace;assembly=packageName"
x:Class="Your.Another.Control.Namespace.DetailedPicker"
x:Name="MyThisReference">
<ContentView.Content>
<Grid>
<!-- Your label and picker goes here -->
<!-- ... -->
ItemsSource="{Binding PickerItemsSource, Source={x:Reference MyThisReference}}"
<!-- ... -->
</Grid>
</ContentView.Content>
</ContentView>

希望对你有帮助。

关于xamarin - ItemsSource 可绑定(bind)属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49360777/

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