WPF - Access Usercontrol of a selected Tabitem

Asked

Viewed 59 times

0

I own a Tabcontrol with several Tabitems, that I have separated the contents into Usercontrols to organize the code. But they all have a Textbox in common of which I want to get the value on a Button on Mainwindow.

I am new in WPF, I’m still learning, I thought I’d expose the value of Textbox on a public property in each Usercontrol, then get the Tabitem selected ((TabItem)TabControlMain.SelectedItem), and get the object Usercontrol internal to access such property (could use an interface with a Get method). The problem is that I can’t get this Usercontrol, I don’t know how to do.

I would like to know how to do something like that, or, if that is an inappropriate solution to WPF, I wonder how I could structure my code for such a case: several Tabitems and get internal values from the window that has the Tabcontrol, preferably separated by files (as with Usercontrols).

1 answer

1


I solved the problem!

Below is an outline that demonstrates my solution:

var tabSelecionada = (TabItem)TabControlMain.SelectedItem;
var uc = (IInterfaceComGet)tabSelecionada.Content;
var resultado = uc.MétodoGetDaInterface();

And at the Usercontrol:

public partial class MeuUserControl : UserControl, IInterfaceComGet { ... }

Basically, my difficulty was not knowing the property Content.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.