locked
Referencing AppBar button in c# code? RRS feed

  • Question

  • There is an appbar button that the c# code should disable depending on gridview selection. I thought the best way to do that would be when the app bar is opened.
    How does one reference an app bar button in c# code?

    Thanks,

    Rick

    <Page.BottomAppBar>
            <AppBar Padding="10 0" Opened="OnAppBarOpened" Closed="OnAppBarClosed">
                <Grid>
                    <StackPanel Name="LeftCommands" Orientation="Horizontal"
                                HorizontalAlignment="Left">
    
                        <Button Style="{StaticResource AddAppBarButtonStyle}"
                                AutomationProperties.Name="Add Point"
                                Click="OnAddAppBarButtonClick"
                                 />
                        <Button Style="{StaticResource DeleteAppBarButtonStyle}"
                                AutomationProperties.Name="Delete Point"
                                Click="OnDeleteAppBarButtonClick"  
                                x:Name="DeleteWaypointAppBarButton"/>
                    </StackPanel>
                </Grid>
            </AppBar>
        </Page.BottomAppBar>
    

    Monday, July 2, 2012 4:02 PM

Answers

  • You could give it a name:  x:Name="MyAppBarButton"

    Or you could loop throught the child controls of the page, appbar, grid, etc.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    • Marked as answer by Bucolic Geek Monday, July 2, 2012 7:54 PM
    Monday, July 2, 2012 4:17 PM
    Moderator

All replies

  • You could give it a name:  x:Name="MyAppBarButton"

    Or you could loop throught the child controls of the page, appbar, grid, etc.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    • Marked as answer by Bucolic Geek Monday, July 2, 2012 7:54 PM
    Monday, July 2, 2012 4:17 PM
    Moderator
  • Sorry for the dumb question.

    As you can see in the attached code, I did give a button a name. VS and intelli-sense did not recognize the name. So, I started believing there was something more complicated going on. A reboot seemed to help VS.

    Monday, July 2, 2012 7:54 PM
  • I tend to have that happen often, but a reboot is uneccessary. Pressing F6 to compile (successfully or not) will 'attach' the button name to intellisense.
    Monday, July 2, 2012 9:30 PM