0

Hi have a button with click event & tag value binding from an XmlDataProvider;

<Button x:Name="Open" Tag="{Binding XPath=Id}" Content="Open" Click="OpenProject_Click" />

and in my xaml.cs click event code (creates new TabItem, with other page content);

  private void Open_Click(object sender, RoutedEventArgs e)
    {
                var ID = ((Button)sender).Tag;

                TabItem tabitem = new TabItem();
                tabitem.Header = ID;
                tabitem.Tag = ID;
                Frame tabFrame = new Frame();
                Pages.Views.View newTab = new Pages.Views.View(ID);
                tabFrame.Content = newTab;
                tabitem.Content = tabFrame;
                AppTabs.Items.Add(tabitem);
                tabitem.Focus();

    }

Below is my Other Page code;

    public partial class View : Page
{
    Object valueFromPage1;

    public View()
    {
        InitializeComponent();
    }

    public View(Object val)
        : this()
    {
        valueFromPage1 = val;
        this.Loaded += new RoutedEventHandler(View_Loaded);

    }
    void View_Loaded(object sender, RoutedEventArgs e)
    {
        text.Text = "Value passed from page1 is: " + valueFromPage1;
    }
}

Problem is that the value that appears on the other page as System.Xml.XmlElement when it need to be the ID Value (which is a number). Is there away to convert the System.Xml.XmlElement back to the button.Tag value?

BENN1TH
  • 2,003
  • 2
  • 31
  • 42

1 Answers1

1

That the value appears as "System.Xml.XmlElement" indicates that the Tag is an XmlElement. It has an attribute InnerText that contains its value (which should be the Id you are looking for).

var ID = (((Button)sender).Tag as XmlElement).InnerText;
Domysee
  • 12,718
  • 10
  • 53
  • 84
  • @BENN1TH I'm not sure what your XML looks like, you can try using `InnerText` and `InnerHtml` properties, maybe they return the correct value. – Domysee Mar 05 '16 at 07:11
  • @BENN1TH you're welcome. I edited the answer to use InnerText instead of Value. – Domysee Mar 05 '16 at 07:13