UIPickerView的CustomRenderer [英] CustomRenderer for UIPickerView
问题描述
是否可以使 UIPickerView
始终在XAML中定义的位置可见?
It is possible to make a UIPickerView
always visible in place where it is defined in XAML?
标准仅当单击 Title
属性时,此控件的行为才会显示绑定列表,然后从屏幕底部(iOS)或弹出窗口(Android)中显示一个小部件,包含一个列表作为内容。
Standard behavior of this controls shows the binded list only when we clicked Title
property, then from the bottom of the screen (iOS) or in the popup(Android) is showing a widget which contains a list as a content.
我想使它从一开始就在定义它的位置(而不是在小部件中)可见。在 picker
对象中没有类似 Position
的东西。
I would like to make this visible from start and in the place where it is defined (not in the widget). There is no something like Position
in picker
object.
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
List<string> names = new List<string>()
{
"test",
"test 2"
};
if (Control != null)
{
var picker = (UIPickerView)this.Control.InputView;
picker.ShowSelectionIndicator = true;
}
}
推荐答案
I解决了这个问题,并在 GitHub 上提供了示例项目存储库。
I solved this problem and made a sample project repository available on GitHub.
示例代码:
<local:CustomObjectPicker
ItemsSource="{Binding ObjectList}"
SelectedItem="{Binding SelectedItem}"
IsTransparent="true"
TextColor="Blue"
/>
它基于 CustomRenderer
,仅适用在iOS上使用,因为 UIPickerView
是本机iOS控件。
It is based on CustomRenderer
and works only on iOS since UIPickerView
is a native iOS control.
这篇关于UIPickerView的CustomRenderer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!