我有日期选择器,我通过网络服务动态填充它。
<Picker x:Name="picker" Title="Select Something" ItemsSource="{Binding}" ItemDisplayBinding="{Binding Name}"></Picker>
我设置了Title
属性,但是对于UWP,它显示为Label。如何将其设置为UWP的默认值/提示?
任何帮助都将不胜感激。
答案 0 :(得分:1)
正如Digitalsa1nt所说,Picker
没有PlaceholderText
财产。但是,您可以通过custom renderer添加此属性。
<强> CustomPicker.cs 强>
public class CustomPicker : Picker
{
public static readonly BindableProperty PlaceHolderProperty = BindableProperty.Create(
propertyName: "PlaceHolder",
eturnType: typeof(string),
declaringType: typeof(CustomPicker),
defaultValue: default(string));
public string PlaceHolder
{
get { return (string)GetValue(PlaceHolderProperty); }
set { SetValue(PlaceHolderProperty, value); }
}
}
在您的uwp客户端项目中实施CustomPickerRenderer
。
<强> CustomPickerRenderer.cs 强>
[assembly: ExportRenderer(typeof(CustomPicker), typeof(CustomPickerRenderer))]
namespace XamarinPickerDefaultValueTest.UWP
{
public class CustomPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
var element = Element as CustomPicker;
if (Control != null)
{
Control.PlaceholderText = element.PlaceHolder;
}
}
}
}
<强>用法强>
<local:CustomPicker PlaceHolder="Picker something" x:Name="picker"/>