开发者

AG_E_UNKNOWN_ERROR

AM getting AG_E_UNKNOWN_ERROR while adding custom visual state groups to my generic.xaml. here is the code related to custom vsm in my class file.

[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualState(Name = "Selected", GroupName = "SelectionStates")]
[TemplateVisualState(Name = "UnSelected", GroupName = "SelectionStates")]

here is my custom method to call visual manager's GoToState to update the status of my custom states.

    protected void GoToState(bool useTransitions)
    {
        //Common States
        if (!this.IsSelected)
        {
            VisualStateManager.GoToState(this, "Normal", useTransitions);
        }

        //Selection States
        if (this.IsSelected)
        {
            VisualStateManager.GoToState(this, "Selected", useTransitions);
        }
        else
        {
            VisualStateManager.GoToState(this, "UnSelected", useTransitions);
        }

    }

Am calling this GotoState Method on change of my dependency property IsSelected and updating the states appropriately.

Here is how is use in xaml..

<ControlTemplate x:Key="tabNavigationItemTemplate" TargetType="local:TabNavigationItem">

    <vsm:VisualStateManager.VisualStateGroups>
        <vsm:VisualStateGroup x:Name="CommonStates">
            <vsm:VisualState开发者_如何学JAVA x:Name="Normal"/>
        </vsm:VisualStateGroup>
        <vsm:VisualStateGroup x:Name="SelectionStates">
            <vsm:VisualState x:Name="Selected">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_TabNavigationItemButton"
                                                   Storyboard.TargetProperty="Background">
                        <DiscreteObjectKeyFrame KeyTime="0">
                            <DiscreteObjectKeyFrame.Value>
                                <SolidColorBrush Color="#FF3B5A82"/>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </vsm:VisualState>
            <vsm:VisualState x:Name="UnSelected">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_TabNavigationItemButton"
                                                   Storyboard.TargetProperty="Background">
                        <DiscreteObjectKeyFrame KeyTime="0">
                            <DiscreteObjectKeyFrame.Value>
                                <SolidColorBrush Color="Transparent"/>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </vsm:VisualState>
        </vsm:VisualStateGroup>
    </vsm:VisualStateManager.VisualStateGroups>

    <Button x:Name="PART_TabNavigationItemButton" Cursor="Hand" 
                Style="{TemplateBinding TabNavigationItemStyle}" 
                ContentTemplate="{TemplateBinding TabNavigationItemTemplate}"/>
</ControlTemplate>

Am i missing anything here? Thanks in advance.


Hi my problem got resolved after adding a Grid as the root element of my control template.

<ControlTemplate x:Key="tabNavigationItemTemplate" TargetType="local:TabNavigationItem">
    <Grid>
        <vsm:VisualStateManager.VisualStateGroups>
            <vsm:VisualStateGroup x:Name="CommonStates">
                <vsm:VisualState x:Name="Normal"/>
            </vsm:VisualStateGroup>
            <vsm:VisualStateGroup x:Name="SelectionStates">
                <vsm:VisualState x:Name="Selected">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_TabNavigationItemButton"
                                               Storyboard.TargetProperty="Background">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <SolidColorBrush Color="#FF3B5A82"/>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </vsm:VisualState>
                <vsm:VisualState x:Name="UnSelected">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_TabNavigationItemButton"
                                               Storyboard.TargetProperty="Background">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <SolidColorBrush Color="Transparent"/>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </vsm:VisualState>
            </vsm:VisualStateGroup>
        </vsm:VisualStateManager.VisualStateGroups>

        <Button x:Name="PART_TabNavigationItemButton" Cursor="Hand" 
            Style="{TemplateBinding TabNavigationItemStyle}" 
            ContentTemplate="{TemplateBinding TabNavigationItemTemplate}"/>
    </Grid>
</ControlTemplate>


Silverlight contains Animations specifically designed to manage colors.

Try it like this:-

 <vsm:VisualStateGroup x:Name="SelectionStates">
        <vsm:VisualState x:Name="Selected">
            <Storyboard>
                <ColorAnimationUsingKeyFrames Storyboard.TargetName="PART_TabNavigationItemButton"
                                               Storyboard.TargetProperty="(Background).(Color)">
                    <DiscreteColorKeyFrame KeyTime="0" Value="#FF3B5A82" />
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </vsm:VisualState>
        <vsm:VisualState x:Name="UnSelected">
            <Storyboard>
                <ColorAnimationUsingKeyFrames Storyboard.TargetName="PART_TabNavigationItemButton"
                                               Storyboard.TargetProperty="(Background).(Color)">
                    <DiscreteColorKeyFrame KeyTime="0" Value="Transparent" />
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </vsm:VisualState>
    </vsm:VisualStateGroup>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜