locked
Back button problem

    Question

  • Hi,

    In my application I have a page that is like a wizard and I manage wizard steps through visual states. Each step of the wizard is a grid with a page title and a back button; in this way I can bind a different command to each back button.

    I have defined this style for page Back button:

    <Style x:Key="PageBackButtonStyle" TargetType="AppBarButton"> <Setter Property="Icon" Value="Back"/> <Setter Property="Height" Value="95"/> <Setter Property="Margin" Value="10,47,10,0"/> </Style>

    <AppBarButton Style="{StaticResource PageBackButtonStyle}" />

    If I put two AppBarButton in my page with the same PageBackButtonStyle I get this exception:

    XAML parsing failed.
    Failed to assign to property 'Windows.UI.Xaml.Controls.ContentPresenter.Content'. [Line: 0 Position: 0]

    It seems that I can have only one back button in my page.

    Why do I get this exception?


    Sunday, February 16, 2014 7:38 AM

Answers

  • Hi OasisLiveForever,

    After consult with senior engineers, currently we do not have a suitable explanation for you. However we will keep this on notes, and thank you for reporting this.

    But as a workaround, we would not suggest you to use Style with Icon property directly for two appbarbuttons. Use separate style should be ok.

    And as you mentioned, you would like to switch the visibility through visual states, you could also try to style one appbarbutton through visual states.

    --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, February 20, 2014 3:06 AM
    Moderator

All replies

  • Hi OasisLiveForever,

    Yes, I can reproduce this issue, I cannot have following code in my XAML, I have to comment one of the AppBarButton.

            <AppBar>
                <StackPanel Orientation="Horizontal">
                    <AppBarButton Style="{StaticResource PageBackButtonStyle}" />
                    <AppBarButton Style="{StaticResource PageBackButtonStyle}" />
                </StackPanel>
            </AppBar>
    

    I think the problem is on the Icon property, if you comment the Icon setter in Style, you should be able to find the page is working now even you did not comment the AppBarButton line.

            <Style x:Key="PageBackButtonStyle" TargetType="AppBarButton">
                <!--<Setter Property="Icon" Value="Back"/>-->
                <Setter Property="Height" Value="95"/>
                <Setter Property="Margin"  Value="10,47,10,0"/>
            </Style>

    This somehow means Symbol enumeration cannot be applied with Style for AppBarButton for using more than once. (Not totally sure, there is no explanation on MSDN for this)

    However, I want to know why you set two back button on one page, it might confuse your app user which one is the correct button, why not use other icons instead.

    --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.


    Monday, February 17, 2014 6:12 AM
    Moderator
  • Hi,

    in my page there is only one back button visible at a time. Since each back button has a different behavior, it's easier for me to have different back buttons and switch their visibility through visual states.

    Monday, February 17, 2014 7:17 AM
  • Hi OasisLiveForever,

    After consult with senior engineers, currently we do not have a suitable explanation for you. However we will keep this on notes, and thank you for reporting this.

    But as a workaround, we would not suggest you to use Style with Icon property directly for two appbarbuttons. Use separate style should be ok.

    And as you mentioned, you would like to switch the visibility through visual states, you could also try to style one appbarbutton through visual states.

    --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, February 20, 2014 3:06 AM
    Moderator