Aggiornare dinamicamente l'ApplicationBarIconButton (it-IT)

Aggiornare dinamicamente l'ApplicationBarIconButton (it-IT)

NOTA: le risorse indicate nel presente articolo sono disponibili solo in lingua Inglese

Poichè l'ApplicationBar non è un DependencyObject e non fa parte della struttura visiva, FindElement non è in grado di individuare gli elementi nell'ApplicationBar per i quali x:Name è impostato.  Questi membri saranno nulli.

 

Per questo motivo, la soluzione migliore può essere inizializzare l'ApplicationBar utilizzando il code behind e mantenere i riferimenti agli elementi che devono essere cambiati dinamicamente.

 

Nel codice in basso si può notare che il riferimento a SaveEdit viene mantenuto e SaveEdit.IsEnabled è aggiornato ad ogni pressione di un tasto all'interno della 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;

}

 

Articolo originale: http://myfun.spaces.live.com/blog/cns!AC1291870308F748!531.entry

 



Altre lingue

Questo articolo è disponibile anche nelle seguenti lingue:

English (en-US)

Deutsch (de-DE)

Brazilian Portuguese (pt-BR)

Leave a Comment
  • Please add 3 and 6 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Luigi Bruno edited Revision 3. Comment: Added the "Italian Wiki Articles" tag to the tag list.

  • Luigi Bruno edited Revision 2. Comment: Added a link in the "Altre lingue" section. Added the "Translated into Italian" tag.

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

  • Luigi Bruno edited Original. Comment: Added the "Altre lingue" section.

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
  • Luigi Bruno edited Original. Comment: Added the "Altre lingue" section.

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

  • Luigi Bruno edited Revision 2. Comment: Added a link in the "Altre lingue" section. Added the "Translated into Italian" tag.

  • Luigi Bruno edited Revision 3. Comment: Added the "Italian Wiki Articles" tag to the tag list.

Page 1 of 1 (4 items)