Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当值通过转换器以应用按钮Bg时,VisualStateManager不工作_C#_Xaml_Windows Phone 8 - Fatal编程技术网

C# 当值通过转换器以应用按钮Bg时,VisualStateManager不工作

C# 当值通过转换器以应用按钮Bg时,VisualStateManager不工作,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我通过转换器应用按钮的背景色。起初,它被正确地应用,但在它被悬停或按下后,背景色将永远消失,不再回来 期望的行为 默认状态 盘旋 悬停状态后 我的问题 悬停状态结束时,橙色背景不再显示 实施 按钮使用 <Button Content="Continue" Style="{StaticResource ButtonAnyColorStyle}"> <Button.Background> <SolidColorBrush Color="{B

我通过转换器应用按钮的背景色。起初,它被正确地应用,但在它被悬停或按下后,背景色将永远消失,不再回来

期望的行为

默认状态

盘旋

悬停状态后

我的问题

悬停状态结束时,橙色背景不再显示

实施

按钮使用

<Button Content="Continue" Style="{StaticResource ButtonAnyColorStyle}">
    <Button.Background>
        <SolidColorBrush Color="{Binding something, Converter={StaticResource PanelBgColorConverter}, Mode=TwoWay}"  />
    </Button.Background>
</Button>
请注意,如果颜色通过XAML作为StaticResource传递,则该行为是完美的。问题在于转换值

<Style x:Key="ButtonAnyColorStyle" TargetType="Button">
    <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid Background="Transparent">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal">
                            </VisualState>
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground"
                                                                   Storyboard.TargetName="ContentContainer">
                                        <DiscreteObjectKeyFrame KeyTime="0"
                                                                Value="{Binding Path=Background, ElementName=ButtonBackground}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background"
                                                                   Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0"
                                                                Value="{Binding Path=Foreground, ElementName=ContentContainer}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush"
                                                                   Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0"
                                                                Value="{Binding Path=Background, ElementName=ButtonBackground}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground"
                                                                   Storyboard.TargetName="ContentContainer">
                                        <DiscreteObjectKeyFrame KeyTime="0"
                                                                Value="{Binding Path=Background, ElementName=ButtonBackground}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background"
                                                                   Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0"
                                                                Value="{Binding Path=Foreground, ElementName=ContentContainer}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush"
                                                                   Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0"
                                                                Value="{Binding Path=Background, ElementName=ButtonBackground}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Disabled">
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                                                   Storyboard.TargetName="ButtonBackground">
                                        <EasingDoubleKeyFrame KeyTime="0"
                                                              Value="0.2" />
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Border x:Name="ButtonBackground"
                            Background="{TemplateBinding Background}"
                            CornerRadius="12"
                            BorderThickness="1"
                            Margin="{StaticResource PhoneTouchTargetOverhang}">
                        <ContentControl x:Name="ContentContainer"
                                        ContentTemplate="{TemplateBinding ContentTemplate}"
                                        Content="{TemplateBinding Content}"
                                        Foreground="{TemplateBinding Foreground}"
                                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        Padding="{TemplateBinding Padding}"
                                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
 public class PanelBgColorConverter : IValueConverter
 {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is something)
        {
            switch ((something)value)
            {
                case something.AppTheme:
                    return Application.Current.Resources["AppThemeColorOnly"];

                case something.Phone:
                    return Application.Current.Resources["AppGreenColorOnly"];

                case something.Email:
                    return Application.Current.Resources["AppYellowColorOnly"];

                default:
                    return Colors.Transparent;
            }
        }
        else return Colors.Transparent;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}