locked
How to change the style of a button programmatically in C# editor in Visual Studio 2012 Express for Windows 8

    Question

  • I have created a new xaml page MyOwnStyles.xaml in the Common folder. It contains the new styles of buttons. Now the thing is that I want to change style of the buttons in C# editor.. Specifically I need to do this the Play Button.. When I click the play button it should change to pause button & again when I click it should change to play button.. When I'm trying to do this, it's throwing an exception System.Runtime.InteropServices.COMException... Don't know the reason.. Please need help ASAP...
    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
        <Style x:Key="MyButtonStyle" TargetType="ButtonBase">
            <Setter Property="Foreground" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
            <Setter Property="VerticalAlignment" Value="Stretch"/>
            <Setter Property="FontFamily" Value="Segoe UI Symbol"/>
            <Setter Property="FontWeight" Value="Normal"/>
            <Setter Property="FontSize" Value="20"/>
            <Setter Property="AutomationProperties.ItemType" Value="App Bar Button"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ButtonBase">
                        <Grid x:Name="RootGrid" Width="100" Background="Transparent">
                            <StackPanel VerticalAlignment="Top" Margin="0,12,0,11">
                                <Grid Width="40" Height="40" Margin="0,0,0,5" HorizontalAlignment="Center">
                                    <TextBlock x:Name="BackgroundGlyph" Text="&#xE0A8;" FontFamily="Segoe UI Symbol" FontSize="53.333" Margin="-4,-19,0,0" Foreground="{StaticResource AppBarItemBackgroundThemeBrush}"/>
                                    <TextBlock x:Name="OutlineGlyph" Text="&#xE0A7; " FontFamily="Segoe UI Symbol" FontSize="53.333" Foreground="Green" Margin="-4,-19,0,0"/>
                                    <ContentPresenter x:Name="Content" HorizontalAlignment="Center" Margin="-1,-1,0,0" VerticalAlignment="Center"/>
                                </Grid>
                                <TextBlock
                                    x:Name="TextLabel"
                                    Text="{TemplateBinding AutomationProperties.Name}"
                                    Foreground="{StaticResource AppBarItemForegroundThemeBrush}"
                                    Margin="0,0,2,0"
                                    FontSize="12"
                                    TextAlignment="Center"
                                    Width="88"
                                    MaxHeight="32"
                                    TextTrimming="WordEllipsis"
                                    Style="{StaticResource BasicTextStyle}"/>
                            </StackPanel>
                            <Rectangle
                                    x:Name="FocusVisualWhite"
                                    IsHitTestVisible="False"
                                    Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
                                    StrokeEndLineCap="Square"
                                    StrokeDashArray="1,1"
                                    Opacity="0"
                                    StrokeDashOffset="1.5"/>
                            <Rectangle
                                    x:Name="FocusVisualBlack"
                                    IsHitTestVisible="False"
                                    Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
                                    StrokeEndLineCap="Square"
                                    StrokeDashArray="1,1"
                                    Opacity="0"
                                    StrokeDashOffset="0.5"/>
    
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="ApplicationViewStates">
                                    <VisualState x:Name="FullScreenLandscape"/>
                                    <VisualState x:Name="Filled"/>
                                    <VisualState x:Name="FullScreenPortrait">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextLabel" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Width">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="60"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Snapped">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextLabel" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Width">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="60"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="PointerOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Green"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPointerOverForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="OutlineGlyph" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="SkyBlue"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPressedForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="OutlineGlyph" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemDisabledForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemDisabledForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextLabel" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemDisabledForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimation
                                                    Storyboard.TargetName="FocusVisualWhite"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="1"
                                                    Duration="0"/>
                                            <DoubleAnimation
                                                    Storyboard.TargetName="FocusVisualBlack"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="1"
                                                    Duration="0"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused" />
                                    <VisualState x:Name="PointerFocused" />
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="CheckStates">
                                    <VisualState x:Name="Checked">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="0" Storyboard.TargetName="OutlineGlyph" Storyboard.TargetProperty="Opacity"/>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundCheckedGlyph" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPressedForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unchecked"/>
                                    <VisualState x:Name="Indeterminate"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
        <Style x:Key="SkipBackMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="SkipBackAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Skip Back"/>
            <Setter Property="Content" Value="&#xE100;"/>
        </Style>
        <Style x:Key="SkipAheadMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="SkipAheadAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Skip Ahead"/>
            <Setter Property="Content" Value="&#xE101;"/>
        </Style>
        <Style x:Key="PlayMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="PlayAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value=" "/>
            <Setter Property="Content" Value="&#xE102;"/>
        </Style>
        <Style x:Key="PauseMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="PauseAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value=" "/>
            <Setter Property="Content" Value="&#xE103;"/>
        </Style>
        <Style x:Key="EditMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="EditAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Edit"/>
            <Setter Property="Content" Value="&#xE104;"/>
        </Style>
        <Style x:Key="SaveMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="SaveAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value=""/>
            <Setter Property="Content" Value="&#xE105;"/>
        </Style>
        <Style x:Key="DeleteMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="DeleteAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Delete"/>
            <Setter Property="Content" Value="&#xE106;"/>
        </Style>
        <Style x:Key="DiscardMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="DiscardAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Discard"/>
            <Setter Property="Content" Value="&#xE107;"/>
        </Style>
        <Style x:Key="RemoveMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="RemoveAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Remove"/>
            <Setter Property="Content" Value="&#xE108;"/>
        </Style>
        <Style x:Key="AddMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="AddAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Add"/>
            <Setter Property="Content" Value="&#xE109;"/>
        </Style>
        <Style x:Key="NoMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="NoAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="No"/>
            <Setter Property="Content" Value="&#xE10A;"/>
        </Style>
        <Style x:Key="YesMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="YesAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Yes"/>
            <Setter Property="Content" Value="&#xE10B;"/>
        </Style>
        <Style x:Key="MoreMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="MoreAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="More"/>
            <Setter Property="Content" Value="&#xE10C;"/>
        </Style>
        <Style x:Key="RedoMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="RedoAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Redo"/>
            <Setter Property="Content" Value="&#xE10D;"/>
        </Style>
        <Style x:Key="UndoMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="UndoAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Undo"/>
            <Setter Property="Content" Value="&#xE10E;"/>
        </Style>
        <Style x:Key="HomeMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="HomeAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Home"/>
            <Setter Property="Content" Value="&#xE10F;"/>
        </Style>
        <Style x:Key="OutMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="OutAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Out"/>
            <Setter Property="Content" Value="&#xE110;"/>
        </Style>
        <Style x:Key="NextMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="NextAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value=" "/>
            <Setter Property="Content" Value="&#xE101;"/>
        </Style>
        <Style x:Key="PreviousMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="PreviousAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value=" "/>
            <Setter Property="Content" Value="&#xE100;"/>
        </Style>
        <Style x:Key="FavoriteMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="FavoriteAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Favorite"/>
            <Setter Property="Content" Value="&#xE113;"/>
        </Style>
        <Style x:Key="PhotoMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="PhotoAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Photo"/>
            <Setter Property="Content" Value="&#xE114;"/>
        </Style>
        <Style x:Key="SettingsMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="SettingsAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Settings"/>
            <Setter Property="Content" Value="&#xE115;"/>
        </Style>
    
    
    
        <Style x:Key="VideoMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="VideoAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Video"/>
            <Setter Property="Content" Value="&#xE116;"/>
        </Style>
        <Style x:Key="RefreshMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="RefreshAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Refresh"/>
            <Setter Property="Content" Value="&#xE117;"/>
        </Style>
        <Style x:Key="DownloadMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="DownloadAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Download"/>
            <Setter Property="Content" Value="&#xE118;"/>
        </Style>
        <Style x:Key="MailMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="MailAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Mail"/>
            <Setter Property="Content" Value="&#xE119;"/>
        </Style>
        <Style x:Key="SearchMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="SearchAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Search"/>
            <Setter Property="Content" Value="&#xE11A;"/>
        </Style>
        <Style x:Key="HelpMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="HelpAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Help"/>
            <Setter Property="Content" Value="&#xE11B;"/>
        </Style>
        <Style x:Key="UploadMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="UploadAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Upload"/>
            <Setter Property="Content" Value="&#xE11C;"/>
        </Style>
        <Style x:Key="EmojiMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="EmojiAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Emoji"/>
            <Setter Property="Content" Value="&#xE11D;"/>
        </Style>
        <Style x:Key="TwoPageMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="TwoPageAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Two Page"/>
            <Setter Property="Content" Value="&#xE11E;"/>
        </Style>
        <Style x:Key="LeaveChatMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="LeaveChatAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Upload"/>
            <Setter Property="Content" Value="&#xE11F;"/>
        </Style>
        <Style x:Key="MailForwardMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="MailForwardAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Forward Mail"/>
            <Setter Property="Content" Value="&#xE120;"/>
        </Style>
        <Style x:Key="ClockMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="ClockAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Clock"/>
            <Setter Property="Content" Value="&#xE121;"/>
        </Style>
        <Style x:Key="SendMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="SendAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Send"/>
            <Setter Property="Content" Value="&#xE122;"/>
        </Style>
        <Style x:Key="CropMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="CropAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Crop"/>
            <Setter Property="Content" Value="&#xE123;"/>
        </Style>
        <Style x:Key="RotateCameraMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="RotateCameraAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Rotate Camera"/>
            <Setter Property="Content" Value="&#xE124;"/>
        </Style>
        <Style x:Key="PeopleMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="PeopleAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="People"/>
            <Setter Property="Content" Value="&#xE125;"/>
        </Style>
        <Style x:Key="ClosePaneMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="ClosePaneAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Close Pane"/>
            <Setter Property="Content" Value="&#xE126;"/>
        </Style>
        <Style x:Key="OpenPaneMyButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource MyButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="OpenPaneAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Open Pane"/>
            <Setter Property="Content" Value="&#xE127;"/>
        </Style>

    <Button x:Name="Play" Style="{StaticResource PlayMyButtonStyle}" Grid.Column="0" Height="96" RenderTransformOrigin="0.5,0.5" Margin="2,0,0,0" Click="Play_Click">

    private void Play_Click(object sender, RoutedEventArgs e)
            {
                Play.Style = Resources["PauseAppBarButtonStyle"] as Style;
            }
    Please help ASAP..
    Thursday, March 6, 2014 4:24 AM

Answers

  • Hi sourav,

    I did not see there is a "PauseAppBarButtonStyle" in your style list, the system could not find the correct style, an exception will be thrown definitely.

    You could try to modify the code as below to see if the code works.

            private void Play_Click(object sender, RoutedEventArgs e)
            {
                Play.Style = Resources["PauseMyButtonStyle"] as Style;
            }
    --James

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Thursday, March 6, 2014 7:19 AM
    Moderator

All replies

  • Hi sourav,

    I did not see there is a "PauseAppBarButtonStyle" in your style list, the system could not find the correct style, an exception will be thrown definitely.

    You could try to modify the code as below to see if the code works.

            private void Play_Click(object sender, RoutedEventArgs e)
            {
                Play.Style = Resources["PauseMyButtonStyle"] as Style;
            }
    --James

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Thursday, March 6, 2014 7:19 AM
    Moderator
  • Hi James..

    Actually I mistakenly uploaded the wrong code..

    I have used the code earlier which you mentioned in the above statement.. But still it is throwing the same exception.. Also showing that the handler has not been handled properly.. Little more suggestions please..

    Thursday, March 6, 2014 4:21 PM