[英]Custom Control Entry not getting set the Place Holder Color Bindable Property
我有一个自定义控件,它有一个日期选择器,但是 PlaceHolderColor 没有被设置并且没有影响。
public Color PlaceHolderColorText
{
get =>
(Color)GetValue(PlaceHolderColorProperty);
set => SetValue(PlaceHolderColorProperty,
value);
}
public static readonly BindableProperty
PlaceHolderColorProperty =
BindableProperty.Create(nameof(PlaceHolderColor),
typeof(Color),
typeof(DateTimePicker2),Color.Black , BindingMode.TwoWay,
propertyChanged: OnPlaceHodlerColorChanged);
我正在创建动态条目
public Entry _dayEntry { get; private set; } = new Entry() {
TabIndex = 0, Placeholder = "dd", Keyboard = Keyboard.Numeric,
WidthRequest = 60, HorizontalOptions = LayoutOptions.Start };
public Entry _monthEntry { get; private set; } = new Entry() {
TabIndex = 1, Placeholder = "MM", Keyboard = Keyboard.Numeric,
WidthRequest = 60, HorizontalOptions = LayoutOptions.Start };
但是我不确定我在这里需要什么来获得正确应用于条目的价值
public static void OnPlaceHodlerColorChanged(BindableObject
bindable, object oldValue, object newValue)
{
var test = newValue;
///do something with new but dont no what.
}
我将这样的条目添加到堆栈的子项中
public DateTimePicker2()
{
BindingContext = this;
_dayEntry.TextChanged += _dayEntry_TextChanged;
_monthEntry.TextChanged += _monthEntry_TextChanged;
_yearEntry.TextChanged += _yearEntry_TextChanged;
_dayEntry.TextColor= TextColor;
_monthEntry.TextColor= TextColor;
_yearEntry.TextColor= TextColor;
_dayEntry.PlaceholderColor = PlaceHolderColor;
_monthEntry.PlaceholderColor = PlaceHolderColor;
_yearEntry.PlaceholderColor = PlaceHolderColor;
_hourEntry.TextColor= TextColor;
_minsEntry.TextColor= TextColor;
SelectedDateChanged +=DateTimePicker2_SelectedDateChanged;
Content = new StackLayout()
{
Orientation = StackOrientation.Horizontal,
Children =
{ _datePicker,
_timePicker,
_monthEntry,
_dayEntry,
_yearEntry,
_hourEntry,
_minsEntry,
_ampmPicker,
iconButton
}
};
我有点困惑要做什么才能让事件注册占位符颜色以更正您将在这里看到的条目。
_dayEntry.PlaceholderColor = PlaceHolderColor;
提前致谢
正确初始BindableProperty
,名称应与属性相同。
public Color PlaceHolderColor { get => (Color)GetValue(PlaceHolderColorProperty); set => SetValue(PlaceHolderColorProperty, value); } public static readonly BindableProperty PlaceHolderColorProperty = BindableProperty.Create(nameof(PlaceHolderColor), typeof(Color), typeof(DateTimePicker2),Color.Black, BindingMode.TwoWay, propertyChanged: OnPlaceHodlerColorChanged);
OnPlaceHodlerColorChanged
事件在属性值更改时触发,因此您需要在 Entry.PlaceholderColor 上手动设置它。
public static void OnPlaceHodlerColorChanged(BindableObject bindable, object oldValue, object newValue) { Color test = newValue as Color; var control = (DateTimePicker2)bindable; control._dayEntry.PlaceholderColor = test; control._monthEntry.PlaceholderColor = test; control._yearEntry.PlaceholderColor = test; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.