Hi, I have a list box from an XML file, and each item I have given them a button data template so that I can register easily. One click event on each item
I would love to receive the content of the button that was clicked to do some query
This is my code
XAM < / P>
& lt; List Box Name = "Listbox 1" & gt; & Lt; ListBox.ItemsSource & gt; & Lt; Binding source = "{static resource keyword lib}" XPath = "position / keyword / word" /> & Lt; /ListBox.ItemsSource> & Lt; ListBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; Button content = "{binding}" click = "keyword_lick" /> & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; / ListBox & gt; After hours of googling for the solution. I know that I should use the sender with click event, and it works fine for the normal button, there was no word here.
Private Zero Keyword Tag (Object Sender, RoutedEventArgs e) {button btn = (button) this; String keyword = btn Content Toasting (); MessageBox.Show (keyword); } The message box displayed "System.Xml.XmlElement" instead of the button content.
Thanks a lot to anyone on this can help me. I spend so much on this, and I think the solution is just a line code.
Cast the contents of the button in a System.Xml.XmlElement. Then use the entote property of this element. Or you might have to do some more operations to get your text. It depends on how your XML file has been created.
Rq: When I need to separate several similar controls in the code, then I use the tag. That's why I can set the content and tags independently (required for multi-language applications.) Or 'tag-logic' when selecting tags (prefix / suffix, index, ...) Which simplify handling in the code.
Comments
Post a Comment