Here’s my XAML
<Label x:Name="fileName" Content="{Binding XPath=./name}" MouseDown="copyUrl" />
and here’s my C# code
private void copyUrl(object sender, System.Windows.RoutedEventArgs e)
{
Label lol = (Label)sender;
string fileUrl = lol.Content.ToString();
MessageBox.Show(fileUrl);
}
I expect the output to be data.txt but I get System.Xml.XmlElement instead! What am I casting wrong or missing here?
You need to convert your content from the
XmlElementto a string or access itsInnerXmlproperty. It is just doing an implicitToString()on the bound item.