0
votes

I have button styles which use VisualStateManger. Currently these styles in <Grid.Resources> and working without any error. I tried to move these styles to Resource dictionary and it gives following error. Anyone know why it is working when style is in inside user control and not working when moved to resource dictionary.

the tag 'visualstatemanager.visualstategroups' does not exist in XML namespace http://schemas.microsoft.com/winfx/2006/xaml/presentation

I'm using .Net 3.5

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vsm="clr-namespace:System.Windows;assembly=wpftoolkit"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    >
    <Style x:Key="Home" BasedOn="{StaticResource PagingButton}" TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType='Button'>
                    <Border Name='border' Background='{StaticResource HomeButtonBackground}' CornerRadius='5,5,0,0'>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" >
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background)" Storyboard.TargetName="border">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonBackground}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background)" Storyboard.TargetName="border">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonBackgroundPressed}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>    
</ResourceDictionary>
1
Please post your resource dictionary XAMLGazTheDestroyer
Is this compile error or designer error only?Rohit Vats
@RohitVats Its a runtime errorSampath
@sampath I just posted solution to this below! You've to use the prefix vsm for example <vsm:VisualStateManager.VisualStateGroups>SirH

1 Answers

2
votes

Problem is you're trying to use something from an assembly which is not referenced. you need to add that in the Window/Page tag at the root with other namespaces as

xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"

Then you can use it as

<vsm:VisualStateManager.VisualStateGroups>
  <vsm:VisualStateGroup x:Name="CommonStates">
    <vsm:VisualState x:Name="MouseOver">
      <Storyboard>
        <ColorAnimation Storyboard.TargetName="tickBox"
            Storyboard.TargetProperty="(Rectangle.Fill).
                                (SolidColorBrush.Color)"
            To="PaleGreen" Duration="0:0:0.5" />
      </Storyboard>
    </vsm:VisualState>
  </vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>