ApplicationBarIconButton dynamisch updaten (de-DE)

ApplicationBarIconButton dynamisch updaten (de-DE)

Da die ApplicationBar kein DependencyObject und auch nicht Teil des Visual Trees, die FindElement-Methode wird keine Elemente in der ApplicationBar finden bei denen x:Name gesetzt ist. Diese werden null sein.

Aufgrund dessen ist es manchmal besser die ApplicationBar im Code-Behind zu initialisieren und eine Referenz auf die Elemente, die dynamisch geändert werden sollen, zu halten.

Beachte, dass im folgenden Code die SaveEdit-Referenz erhalten bleibt und SaveEdit.IsEnabled mit jedem Touch der TextBox geupdated wird.

#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;

}

Ursprüngliche Quelle: http://myfun.spaces.live.com/blog/cns!AC1291870308F748!531.entry

Siehe auch


Andere Sprachen


Dieser Artikel ist auch in folgenden Sprachen vorhanden:

English (en-US)

Italian (it-IT)

Brazilian Portuguese (pt-BR)

Leave a Comment
  • Please add 1 and 2 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Horizon_Net edited Revision 4. Comment: added link to portuguese version

  • Horizon_Net edited Revision 3. Comment: added tag

  • Horizon_Net edited Revision 1. Comment: added 'siehe auch' section

  • Horizon_Net edited Original. Comment: updated formatting

Page 1 of 1 (4 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
  • Horizon_Net edited Original. Comment: updated formatting

  • Horizon_Net edited Revision 1. Comment: added 'siehe auch' section

  • Horizon_Net edited Revision 3. Comment: added tag

  • Horizon_Net edited Revision 4. Comment: added link to portuguese version

Page 1 of 1 (4 items)