我为 Metro 应用程序制作了自定义控件,并希望从 Style 中设置其属性。但它的设置者没有被调用。
控制属性:
public int FramesCount
{
get { return _framesCount; }
set
{
_framesCount = value;
if (ImageFileMask != null) ReloadFrames();
}
}
public static readonly DependencyProperty FramesCountProperty =
DependencyProperty.Register(
"FramesCount", typeof(int),
typeof(MyControl), null
);
XAML 风格:
<Style TargetType="controls:MyControl" x:Key="wmLoadingBoxWaiting">
<Setter Property="Width" Value="32"/>
<Setter Property="Height" Value="32"/>
<Setter Property="FramesCount" Value="1"/>
</Style>
和页面 XAML:
<controls:MyControl HorizontalAlignment="Left" Margin="645,185,0,0" VerticalAlignment="Top" Style="{StaticResource wmLoadingBoxWaiting}"/>
标准属性(宽度和高度)设置正确,但 costom 属性 FramesCount 没有。只有当我直接在页面 XAML 中设置它而不是设置样式时,它的设置器才会调用。有人知道我做错了什么吗?