get clicked button content from button styled listbox binded to xml

后端 未结 2 501
渐次进展
渐次进展 2020-12-19 23:23

Hi I have a listbox binded to a xml file, and each item I gave them a button data template so I can easily register a click event to each item.

I would love to get

相关标签:
2条回答
  • 2020-12-19 23:50

    cast the content of the button to an System.Xml.XmlElement. Then use the InnerText property of this element. Or maybe you have to do some more operation to get to your text. It depends on how your XML file is built.

    Rq : when i need to distinguish several identical controls in code, i use Tags. So i can set content and Tag independantly (required for multi-language apps.) or even use a 'tag-logic'when choosing the Tag (prefixe/suffixes, index, ...) which simplify handling in code.

    0 讨论(0)
  • 2020-12-20 00:00

    I know you got the answer but, this is another type to get the content of button.

        private void keyword_Click(Object sender, RoutedEventArgs e)
        { 
           var keyword= (e.Source as Button).Content.ToString();
           MessageBox.Show(keyword);
         }
    
    0 讨论(0)
提交回复
热议问题