На этот вопрос ответили здесь: Установка пользовательского свойства на странице WPF / Silverlight
Причина этой проблемы также объясняется в ссылке.
У вас есть несколько вариантов назначения вашего пользовательского свойства зависимости в Xaml
Вариант 1 . Создайте базовый класс для Page, куда вы добавите свой DP
MenuPage.xaml
<dgCommon:MenuPageBase x:Class="dgCommon.MenuPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dgCommon="clr-namespace:dgCommon"
MenuIconStyle="{StaticResource MenuButtonStyle}">
<!--...-->
</dgCommon:MenuPageBase>
MenuPage.xaml.cs
public partial class MenuPage : MenuPageBase
{
// ...
}
MenuPageBase.cs
public class MenuPageBase : Page
{
public static readonly DependencyProperty MenuIconStyleProperty =
DependencyProperty.Register("MenuIconStyle",
typeof(Style),
typeof(MenuPage),
new UIPropertyMetadata(null));
public Style MenuIconStyle
{
get { return (Style)GetValue(MenuIconStyleProperty); }
set { SetValue(MenuIconStyleProperty, value); }
}
}
Опция 2. Реализация статических методов get и set для MenuIconStyle
MenuPage.xaml
<Page x:Class="dgCommon.MenuPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dgCommon="clr-namespace:dgCommon"
dgCommon.MenuPage.MenuIconStyle="{StaticResource MenuButtonStyle}">
MenuPage.xaml.cs
public partial class MenuPage : Page
{
public static readonly DependencyProperty MenuIconStyleProperty =
DependencyProperty.Register("MenuIconStyle",
typeof(Style),
typeof(MenuPage),
new UIPropertyMetadata(null));
public Style MenuIconStyle
{
get { return (Style)GetValue(MenuIconStyleProperty); }
set { SetValue(MenuIconStyleProperty, value); }
}
public static void SetMenuIconStyle(Page element, Style value)
{
element.SetValue(MenuIconStyleProperty, value);
}
public static Style GetMenuIconStyle(Page element)
{
return (Style)element.GetValue(MenuIconStyleProperty);
}
// ...
}
Вариант 3. Используйте Attached Properties, как указали другие люди.