c# - Accessing other listbox item controls and properties on button click -


I'm currently compiling an XML file in a list box in C # WPF I added controls within the circle. As follows:

  & gt; Datamapplet X: Key = "Singlettachlelet" & gt; & Lt; Grid height = "30" width = "425" margin = "3,3,0,3" & gt; & Lt; Button Content = "{Binding XPath = NR}" width = "30" style = "{DynamicResource CUEStyle_Button_Inhoudknopje}" template = "{DynamicResource CUEStyle_singlecueknopnummer}" height = "auto" HorizontalAlignment = "left" background = "# FFABCCED "Foreground =" white "IsEnabled =" False "/> & Lt; TextBlock x: name = "name" margin = "54,0,114.667,0" width = "auto" vertical alignment = "center" font system = "16" foreground = "gray" text = "{binding XPath = name}" /> ; & Lt; Button x: Name = "Playbutton" width = "30" style = "{DynamicResource CUEStyle_Button_Groot}" template = "{DynamicResource CUEStyle_Rondknopje}" height = "auto" HorizontalAlignment = "right" Margin = "0,0.55,74.737, -0.55 "Content =" u "fontfamily =" wingdins 3 "foreground =" #ff 0178d3 "opacity =" 1 "borderbrush =" #ff 0178d3 "click =" placquo "/> & Lt; Button width = "30" style = "{DynamicResource CUEStyle_Button_Groot}" template = "{DynamicResource CUEStyle_Rondknopje}" height = "auto" HorizontalAlignment = "right" Margin = "0,0.55,37.071, -0.55" content = "¢" Fontfamili = "Wingdings 2" foreground = "gray" opacity = "0.4" /> & Lt; Button width = "15" style = "{DynamicResource CUEStyle_Button_Groot}" template = "{DynamicResource CUEStyle_kleinloopje}" height = "15" HorizontalAlignment = "left" Margin = "15,0,0, -5.5" content = "Q" FontFamily = "Wingdings 3" foreground = "white" FontWeight = "bold" fONTSIZE = "10.667" opacity = "1" VerticalAlignment = "bottom" BorderBrush = "{x: null}" background = "{x: null}" IsEnabled = "{Binding XPath = loop}" /> & Lt; TextBlock Margin = "0,0,114.667,0" width = "81.07" VerticalAlignment = "center" FONTSIZE = "16" Foreground = "gray" text = "03:02:11" HorizontalAlignment = "right" / & gt; & Lt; / Grid & gt; & Lt; / DataTemplate & gt;  

Now when a play button is clicked, I want to get other properties from that listbox, for example text lessons from how to do this and came with the following: < / P>

  Private Wide PlayQue (Object Sender, System. Rooted Event Erge E) {button playback = (button) Sender; Text box title = (textbox) playback. Datacontext; MessageBox.Show (titel); }  

But the above code gives me an error stating that type textbox is unknown. Do I have something to do with the dataplate so that I can get other items within the template? Or is it possible to access Brother Nodes from a data source?

UPDATE

get answer. Now for future reference:

  Private Zero Button (Object Sender, System.Windows.RoutedEventArgs e) {button playback = (button) Sender; XMLElement Name = (XMLElement) playback. Datacontext; MessageBox.Show (name.InnerText); }  

Returns all the brother values ​​from the item

If you want to access a specific brother, then you can:

  MessageBox.Show (name.SelectSingleNode ("name") InnerXml.); The first problem is that it is not a  textbox   

text box (C # is case sensitive.)

Secondly, it is not possible that your datacontax is a textbox There should be an item in your itemsSource collection. Therefore, if the user clicks on the third button in the list, then you should see the third thing in your itemsSource collection. Since it appears that you are using XML as a data source, I think the item should be XElement or XmlElement .

I recommend you to text box title = (textbox) playback. Datacontext; at the bottom:

  the excelment element = (excel) playback. Datacontext;  

or

  XML element element = (XMLAlment) playback. Datacontext;  

You must also change your messagebox statement.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -