我添加了一個BarTextColor
屬性,我的自定義頁面Xamarin,像這樣:如何將屬性添加到我可以在默認樣式中使用的Xamarin頁面中?
public static readonly BindableProperty BarTextColorProperty = BindableProperty.Create("BarTextColor", typeof(Color), typeof(MyCustomPage), Color.Default);
public Color BarTextColor
{
get { return (Color)GetValue(BarTextColorProperty); }
set { SetValue(BarTextColorProperty, value); UpdateInnerViews(); }
}
但是,當我嘗試設置一個全球性的風格,我的App.xaml像這樣:
<Style TargetType="myapp:MyCustomPage">
<Setter Property="BarTextColor" Value="{StaticResource BarTextColor}"/>
</Style>
我得到這個錯誤:
Property 'BarTextColor' must be a DependencyProperty to be set with a Setter
這:
The property "BarTextColor" is not a DependencyProperty. To be used in markup, non-attached properties must be exposed on the target type with an accessible instance property "BarTextColor". For attached properties, the declaring type must provide static "GetBarTextColor" and "SetBarTextColor" methods.
怎麼回事? github上的Xamarin源碼全部使用BindableProperty
而不是DependencyProperty
,所以爲什麼我不能?
(我使用Visual Studio 2013社區與Xamarin 2.3.1,如果它事項)
謝謝,但我需要在全球範圍內的風格我的網頁。我不能只在每個頁面上設置明確的樣式。所以我需要沒有Key的版本。 – Simon
@Simon增加了一個建議。 –
謝謝。這就是我目前正在做的事情,但隨着頁面數量的增加,它不可持續。我真的需要設置全球風格。 – Simon