Activate maintenance buttons for all my views

0

I'm working with WPF, Visual Studio 2015

  • I have a main view that is my home view, in which a TabControl and its respective TabItem fall at run time.

  • In the TabItem at the moment of activating them (click) calls its respective UserControl that makes the time of another view where all the controls are.

  • Then the sequence is Main view - > TabControl (UserControl) - > Views (UserControl [where I have the controls to enter information to the app as show as well]).

The reference to be able to create that technique of calling views take it from here Using ContentTemplateSelector in Tab Control View

The issue is that when the UserControl for example called usrUsuario enters the tabUser check that it is inside the tab for when you click on any button of the maintenance check that there is a usrControl if there is an event is executed. the usrControl.

For that I have created an interface that I implement in all the users that have to do maintenance.

public interface ICommandAction
{
    void Nuevo();
    void Guardar();
    void Eliminar();
}

Until then I have the events of each view (usr)

public partial class UsuarioView : UserControl, ICommandAction
{
    public UsuarioView()
    {
        InitializeComponent();
    }

    public void Eliminar()
    {
        throw new NotImplementedException();
    }

    public void Guardar()
    {
        throw new NotImplementedException();
    }

    public void Nuevo()
    {
        throw new NotImplementedException();
    } 
}

Now the issue is to check if there is a usr (UserControl) inside a tab and communicate it to the main View that receives the TabControl and this to the view (usr) that enter each Tab.

  • First I decided to work on the usrTabControl which receives the views, to validate if it has a view inside the tab.

    public void Guardar()
    {
        if (_myTabItemModel.CurrentMyTabContentViewModel != null)
            _eventHub.Publish(new ActionBotonMenu { Flag = true });
    }
    
  • And that information send it to the main view through events, but the issue is that I do not call any of these usr that fall in the I mean I do not usrUsuario usr = new usrUsuario(); usr.Show();

The topic is a bit extensive, I hope to have explained to me, how could I validate from the main View that in the usrTabControl there is a usrUsuario or the one that was active to be able to send info when they click on the Save button?

    
asked by Pedro Ávila 10.10.2017 в 17:14
source

1 answer

1

So you can know if your TabItem (imagine it's called TabLista) has something inside, in this case an UsrControl:

if (tabLista.Content != null) //si tiene algo
{
    //El tabItem tiene algo
    if (tabLista.Content.GetType() == typeof(UsrControl))
    {
        //tiene un UsrControl
    }
    else
    {
        //No tiene un UserControl, pero tiene otra cosa
    }
}
else
{
    //El tabItem no tiene nada de nada 
}

The question is a little confusing but I think this can help you.

Now, if you want to know if your TabControl has TabItems with a for cycle, you can

for (int i = 0; i < control.Items.Count; i++)
{
    TabItem tab = (TabItem)control.Items[i];
    //if(tab.Content != null)
    //{
        //    //etc......
    //}
}

And with that you can check what each Tab has, its property Visibility, IsEnabled, etc. Greetings.

    
answered by 11.10.2017 в 00:47