我正在尝试创建一个带有两个项目(Label
和 DatePicker
)的 ContentView
,并且我需要将第二个项目的 ItemsSource
作为可绑定属性发送。
我尝试使用 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
作为BindableProperty
绑定到ContentView
?