我試圖實現從DatePicker派生的自定義控件。此控件將具有Android和iOS渲染器。我需要爲這個控件添加FontSize屬性,我將在渲染器類中使用它。自定義FontSize應接受字符串文字
這是我實現字號屬性的:
public static BindableProperty FontSizeProperty = BindableProperty.Create<ExDatePicker, double>(o => o.FontSize, 16d, propertyChanged: OnFontSizeChanged);
public double FontSize
{
get { return (double)GetValue(FontSizeProperty); }
set { SetValue(FontSizeProperty, value); }
}
private static void OnFontSizeChanged(BindableObject bindable, double oldvalue, double newvalue)
{
var control = bindable as ExDatePicker;
if (control != null)
{
control.FontSize = newvalue;
}
}
我需要的是同樣的方式來使用這個屬性能力作爲本地字號性質的作品,即我需要可以設置類似
FontSize="Small"
in xaml code。 這可能嗎?
編輯: 在xamarin表單中,可以使用FontSize =「Small」來設置不同平臺的設備特定字體大小。這autmagically轉換「小」串入雙用
Device.GetNamedSize(NamedSize.Small, typeof(ExtednedDatePicker))
我不知道如何添加這個自動轉換爲創建字號不Xamarin用戶窗體庫
在這種情況下,你能不能有字體大小屬性作爲一個對象,並在你的'OnFontSizeChanged'方法嘗試確定它是否是'string'或'double',如果它是一個字符串使用'開關聲明「來設置大小? – user1
將檢查此解決方案 – Dzior
嘗試像這樣在xaml頁面FontSize =「{StaticResource FontSizeSmall}」添加此資源 16 –
Jayasri