Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.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# 如何在WindowsPhone7中突出显示用户界面上单击的按钮_C#_Silverlight_Button_Windows Phone 7_Highlighting - Fatal编程技术网

C# 如何在WindowsPhone7中突出显示用户界面上单击的按钮

C# 如何在WindowsPhone7中突出显示用户界面上单击的按钮,c#,silverlight,button,windows-phone-7,highlighting,C#,Silverlight,Button,Windows Phone 7,Highlighting,我正在用C#开发WindowsPhone7应用程序。我对silverlight是新手。我的应用程序中有多个按钮用于不同的用途。我正在这些按钮中的一个按钮上执行单击操作。现在,我想在用户界面屏幕上向用户显示所选按钮。所以我想突出显示选中的按钮,这样用户界面将以不同于屏幕上其他按钮的方式显示特定的单击按钮。之前我尝试过以下场景 你能告诉我怎样突出显示点击的按钮吗?你能提供我任何代码或链接,通过它我可以解决上述问题吗?如果我做错了什么,请指导我。您似乎在寻找几个按钮上的RadioButton功能。在

我正在用C#开发WindowsPhone7应用程序。我对silverlight是新手。我的应用程序中有多个按钮用于不同的用途。我正在这些按钮中的一个按钮上执行单击操作。现在,我想在用户界面屏幕上向用户显示所选按钮。所以我想突出显示选中的按钮,这样用户界面将以不同于屏幕上其他按钮的方式显示特定的单击按钮。之前我尝试过以下场景


你能告诉我怎样突出显示点击的按钮吗?你能提供我任何代码或链接,通过它我可以解决上述问题吗?如果我做错了什么,请指导我。

您似乎在寻找几个按钮上的RadioButton功能。在这种情况下,您只需使用默认按钮模板重新设置RadioButton的模板,并添加选中按钮的VisualState即可。这个例子将使最新点击的按钮的背景变成红色,我希望这就是你想要的

<StackPanel>
    <RadioButton Style="{StaticResource RadioButtonStyle1}"
                 GroupName="buttonGroup"
                 HorizontalContentAlignment="Center"
                 Content="Some Button"/>
    <RadioButton Style="{StaticResource RadioButtonStyle1}"
                 GroupName="buttonGroup"
                 HorizontalContentAlignment="Center"
                 Content="Some Button 2"/>
</StackPanel>

还有收音机按钮样式1

<Style x:Key="RadioButtonStyle1" TargetType="RadioButton">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
    <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
    <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
    <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
    <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
    <Setter Property="Padding" Value="10,3,10,5"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RadioButton">
                <Grid Background="Transparent">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CheckStates">
                            <VisualState x:Name="Checked">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Red"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Unchecked"/>
                            <VisualState x:Name="Indeterminate"/>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver"/>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Gray"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Disabled">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" 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>

您似乎正在寻找几个按钮上的RadioButton功能。在这种情况下,您只需使用默认按钮模板重新设置RadioButton的模板,并添加选中按钮的VisualState即可。这个例子将使最新点击的按钮的背景变成红色,我希望这就是你想要的

<StackPanel>
    <RadioButton Style="{StaticResource RadioButtonStyle1}"
                 GroupName="buttonGroup"
                 HorizontalContentAlignment="Center"
                 Content="Some Button"/>
    <RadioButton Style="{StaticResource RadioButtonStyle1}"
                 GroupName="buttonGroup"
                 HorizontalContentAlignment="Center"
                 Content="Some Button 2"/>
</StackPanel>

还有收音机按钮样式1

<Style x:Key="RadioButtonStyle1" TargetType="RadioButton">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
    <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
    <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
    <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
    <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
    <Setter Property="Padding" Value="10,3,10,5"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RadioButton">
                <Grid Background="Transparent">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CheckStates">
                            <VisualState x:Name="Checked">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Red"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Unchecked"/>
                            <VisualState x:Name="Indeterminate"/>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver"/>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Gray"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Disabled">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" 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>


您链接的问题中的答案不适合您有什么原因吗?也许这个问题在某种程度上有所不同?它起作用了。但是我应该如何维护单击按钮的状态,以便在应用程序中直观地显示它呢?或者如何更改所选按钮的颜色?我应该写什么代码?请帮助。在我的场景中,我只想单击可用两个按钮中的一个按钮。对于按钮控件,这是一种或种情况。你能帮我一下吗?你的问题不够清楚。。。如果你举一个小的XAML例子来说明你需要做什么,也许会有所帮助。@Shailesh Jaiswal:我正确理解你的问题了吗?或者,当其中一个按钮有焦点时,您只是想要这种效果吗?您链接的问题中的答案对您不起作用有什么原因吗?也许这个问题在某种程度上有所不同?它起作用了。但是我应该如何维护单击按钮的状态,以便在应用程序中直观地显示它呢?或者如何更改所选按钮的颜色?我应该写什么代码?请帮助。在我的场景中,我只想单击可用两个按钮中的一个按钮。对于按钮控件,这是一种或种情况。你能帮我一下吗?你的问题不够清楚。。。如果你举一个小的XAML例子来说明你需要做什么,也许会有所帮助。@Shailesh Jaiswal:我正确理解你的问题了吗?或者,当其中一个按钮具有焦点时,您只是想要这种效果吗?