0

私が間違っていることを理解しようとしています(初めてビジュアルステートで遊んでいます)。誰かが私の問題を指摘できますか?アプリが正常にクラッシュしていません。それ以上の助けはありません。

これがxamlです

<Style TargetType="HyperlinkButton">
    <Setter Property="Foreground" Value="{StaticResource HyperlinkTextBrush}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="HyperlinkButton">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal">
                            <Storyboard>
                                <ColorAnimation BeginTime="0" Duration="0.5" 
                                                Storyboard.TargetName="content"
                                                Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
                                                To="Red" />
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <ColorAnimation BeginTime="0" Duration="0.5"
                                                Storyboard.TargetName="content"
                                                Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
                                                To="White" />
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Grid>
                    <ContentPresenter x:Name="content" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

ありがとう!

4

1 に答える 1

1

修正する必要がある場所は3つあります。

1)VisualStateManager.VisualStateGroupsタグは、のようにルートコントロール内に配置する必要があり、。内には配置GridしないでControlTemplateください。

2)クラスにプロパティContentPresenterがありません。Foregroundただし、このプロパティはContentControlクラスに存在します。このコントロールを置き換えた後、プロパティContentとの明示的なバインディングを追加しますForeground

3)Durationプロパティの値は秒単位である必要があります。Duration="1"1日を意味する式を使用できますが、値0.5によってアプリケーションがクラッシュします。0.5秒はのように見え0:0:0.5ます。

固定スタイルは次のとおりです。

    <Style TargetType="HyperlinkButton">
        <Setter Property="Foreground" Value="{StaticResource HyperlinkTextBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="HyperlinkButton">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.5"
                                            Storyboard.TargetName="content"
                                            Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
                                            To="Red" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.5"
                                            Storyboard.TargetName="content"
                                            Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
                                            To="White" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentControl x:Name="content" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" 
                                        Foreground="{TemplateBinding Foreground}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
于 2011-10-03T20:01:04.183 に答える