Я добавил 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.
Что случилось? Источник Xamarin на github все использует BindableProperty
не DependencyProperty
, так почему я не могу?
(я использую Visual Studio Community 2013 с Xamarin 2.3.1, в случае, если это имеет значение)
Спасибо, но мне нужно глобально стилю мои страницы. Я не могу просто задать явный стиль на каждой странице. Поэтому мне нужна версия без ключа. – Simon
@Simon Добавлено еще одно предложение. –
Спасибо. Это то, что я делаю в данный момент, но это не устойчиво, поскольку количество страниц, которые у меня есть, увеличивается. Мне действительно нужно установить глобальные стили. – Simon