Updating ApplicationBarIconButton Dynamically

Updating ApplicationBarIconButton Dynamically

 

Since the ApplicationBar is not a DependencyObject and not part of the visual tree, FindElement cannot locate Items in the ApplicationBar with x:Name set.  The members will be null.

 

Due to this, it may be best to initialize the ApplicationBar using code behind and hold references to items which need to be dynamically changed.

 

Notice in the code below that SaveEdit reference is held and SaveEdit.IsEnabled is updated with each keypress into the TextBox.

 

#region AppBar

private ApplicationBarIconButton SaveEdit;

private void InitAppBar()

{

ApplicationBar appBar = new ApplicationBar();

appBar = new ApplicationBar();

 

SaveEdit = new ApplicationBarIconButton(new Uri("images/appbar.check.rest.png", UriKind.Relative));

SaveEdit.Click += new EventHandler(OnClick_Check);

//SaveEdit.Text = Strings.Save_button;

appBar.Buttons.Add(SaveEdit);

 

ApplicationBarIconButton CancelEdit = new ApplicationBarIconButton(new Uri("images/appbar.close.rest.png", UriKind.Relative));

CancelEdit.Click += new EventHandler(OnClick_Cancel);

//CancelEdit.Text = Strings.Cancel_button;

appBar.Buttons.Add(CancelEdit);

 

ApplicationBar = appBar;

}

#endregion AppBar

       

 

 

void itemName_KeyDown(object sender, KeyEventArgs e)

{

bool isNameValid = itemName.Text.Length != 0;

           

if ((e.Key == Key.Enter) && isNameValid)

{

SaveAndExit();

}

           

SaveEdit.IsEnabled = isNameValid;

}

 

Original article source: http://myfun.spaces.live.com/blog/cns!AC1291870308F748!531.entry

 



Other Languages

This article is also available in the following languages:

Italian (it-IT)

Deutsch (de-DE)

Brazilian Portuguese (pt-BR)

Leave a Comment
  • Please add 6 and 5 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Carsten Siemens edited Revision 9. Comment: Added tag: has comment

  • Richard Mueller edited Revision 7. Comment: Replace RGB values with color names in HTML to restore colors

  • Richard Mueller edited Revision 6. Comment: Removed (en-US) from title, added tags

  • Luigi Bruno edited Revision 5. Comment: Fixed some links in the "Other Languages" section.

  • Fernando Lugão Veltem edited Revision 4. Comment: added portuguse version

  • Horizon_Net edited Revision 3. Comment: added link to german version

  • Luigi Bruno edited Revision 2. Comment: Added the "Other Languages" section.

  • Luigi Bruno edited Revision 1. Comment: Edited article's title and tags list.

  • Ed Price MSFT edited Original. Comment: Updated title casing and cleared formatting on non-code at bottom.

Page 1 of 1 (9 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
Page 1 of 1 (11 items)