src/controls/dev/AnimatedIcon/Docs/AnimatedIconDevDesign.md
This doc details the technical challenges and specifications of the animated icon control.
[WUXC_VERSION_PREVIEW]
[webhosthidden]
interface IRichAnimatedVisualSource
{
IAnimatedVisual TryCreateAnimatedVisual(Windows.UI.Composition.Compositor compositor);
Windows.Foundation.Collections.IMapView<String, Double> Markers { get; };
void SetColorProperty(String propertyName, Windows.UI.Color value);
};
[WUXC_VERSION_PREVIEW]
[webhosthidden]
unsealed runtimeclass AnimatedIcon : Windows.UI.Xaml.Controls.IconElement
{
AnimatedIcon();
[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
IRichAnimatedVisualSource Source{ get; set; };
[MUX_DEFAULT_VALUE("Normal")]
[MUX_PROPERTY_CHANGED_CALLBACK_METHODNAME("OnAnimatedIconStatePropertyChanged")]
static Windows.UI.Xaml.DependencyProperty StateProperty{ get; };
static void SetState(Windows.UI.Xaml.DependencyObject object, String value);
static String GetState(Windows.UI.Xaml.DependencyObject object);
static Windows.UI.Xaml.DependencyProperty SourceProperty{ get; };
}
Brush Foreground {get;set;} // only accepts solidcolorbrush, no-op otherwise Inherited from IconElement.
Control templates will not (normally) have animated icons in them. Instead they generally have a content presenter or grid who's content is template bound to the controls Icon property, which is of type IconElement. For this reason, in order to set the animated icon properties via the visual states, the animated icon properties need to be attached properties. In addition to that, the template won't generally be setting the property on the animated icon itself, instead it will usually be setting it on the parent. So in the properties setter we will want to also set the property on the targets child (the animated icon) if it exists. Additionally, in animated Icon's loaded event we will want to make sure to grab the properties off the parent in case it was set before we loaded.
An icon button template which has been updated to support using an animated icon in its icon property.
<Button Content="Hello Button" Width="200" Height="40">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Target="Icon.(AnimatedIcon.State)" Value="Normal"/>
</VisualSTate.Setters>
</VisualState>
<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter Target="Icon.(AnimatedIcon.State)" Value="Hover"/>
</VisualSTate.Setters>
</VisualState>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Target="Icon.(AnimatedIcon.State)" Value="Pressed"/>
</VisualSTate.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter
x:Name="ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw" />
<Grid x:Name="Icon" HorizontalAlignment="Right" Content="{TemplateBinding Icon}/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
void SetColorProperty(String propertyName, Windows.UI.Color value);Windows.Foundation.Collections.IMapView<String, Double> Markers { get; };Downsides:
Red Flags: