当我将它附加到xaml元素时,我有一个附加属性我得到一个名为的异常“默认值不能'未设置'”
我的附属属性逻辑
public static DataTemplate GetFooterContentTemplate(DependencyObject obj)
{
return (DataTemplate)obj.GetValue(FooterContentTemplateProperty);
}
public static void SetFooterContentTemplate(DependencyObject obj, DataTemplate value)
{
obj.SetValue(FooterContentTemplateProperty, value);
}
// Using a DependencyProperty as the backing store for GetFooterContentTemplate. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FooterContentTemplateProperty =
DependencyProperty.Register("FooterContentTemplate", typeof(DataTemplate), typeof(RadWindowFooterProperties), new PropertyMetadata(DependencyProperty.UnsetValue));
public static Object GetFooterContent(DependencyObject obj)
{
return (Object)obj.GetValue(FooterContentProperty);
}
public static void SetFooterContent(DependencyObject obj, Object value)
{
obj.SetValue(FooterContentProperty, value);
}
// Using a DependencyProperty as the backing store for RadWindowFooterContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FooterContentProperty =
DependencyProperty.RegisterAttached("FooterContent", typeof(Object), typeof(RadWindowFooterProperties), new PropertyMetadata(DependencyProperty.UnsetValue));
我的XAML:
<Grid x:Name="FooterRoot" Grid.Row="2" MinHeight="42">
<Border Background="{StaticResource ShellFooterBrush}"/>
<Border Background="{DynamicResource ShellTileBrush}"/>
<ContentPresenter Content="{Binding Path=(Local:RadWindowFooterProperties.FooterContent),RelativeSource={RelativeSource Mode=TemplatedParent}}" ContentTemplate="{Binding Path=(Local:RadWindowFooterProperties.FooterContentTemplate),RelativeSource={RelativeSource Mode=TemplatedParent}}" RecognizesAccessKey="True"/>
</Grid>
请让我知道我在哪里做错了。
答案 0 :(得分:2)
答案 1 :(得分:1)
DependencyProperty.UnsetValue
不是依赖项属性的有效默认值。除非您想指定null
以外的默认值,否则根本不需要注册属性元数据。
您还必须将FooterContentTemplateProperty
的声明更改为使用RegisterAttached
而不是Register
:
public static readonly DependencyProperty FooterContentTemplateProperty =
DependencyProperty.RegisterAttached(
"FooterContentTemplate", typeof(DataTemplate), typeof(RadWindowFooterProperties));
public static readonly DependencyProperty FooterContentProperty =
DependencyProperty.RegisterAttached(
"FooterContent", typeof(Object), typeof(RadWindowFooterProperties));