Reputation: 331
I made custom control for metro application and want to set its properties from Style. But it's setters are not called.
Control property:
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:
<Style TargetType="controls:MyControl" x:Key="wmLoadingBoxWaiting">
<Setter Property="Width" Value="32"/>
<Setter Property="Height" Value="32"/>
<Setter Property="FramesCount" Value="1"/>
</Style>
And page XAML:
<controls:MyControl HorizontalAlignment="Left" Margin="645,185,0,0" VerticalAlignment="Top" Style="{StaticResource wmLoadingBoxWaiting}"/>
Standard properties (Width and Height) are setted properly, byt costom property FramesCount does not. Its setter calls only when I set it directly in page XAML instead setting style. Does anybody know what I'm doing wrong?
Upvotes: 0
Views: 891
Reputation: 331
I found some solution:
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),
new PropertyMetadata(false, (d, e) =>
{
(d as MyControl).FramesCount = (int)e.NewValue;
})
);
Upvotes: 0
Reputation: 16361
Change your FramesCount
definition:
public int FramesCount
{
get { return (string)GetValue(FramesCountProperty ); }
set
{
SetValue(FramesCountProperty , value);
if (ImageFileMask != null) ReloadFrames();
}
}
Upvotes: 1