Information on Title - WPF

Asked

Viewed 90 times

2

I have an application where the user can select the company to be worked on. When he selects, I would like this information to go to the Application Title... This is possible?

The attribute Title is in the parent window. Already this event Mousedoubleclick is in a Usercontrol son... This is my doubt, how to pass from the son to the Father..

For now I have this Textblock to add the information in the title:

<TextBlock Text="{Binding Titulo, RelativeSource={RelativeSource FindAncestor,AncestorType=Window}}" HorizontalAlignment="Center" VerticalAlignment="Top"/>

Title:

private string _titulo;

    public string Titulo
    {
        get
        {
            return _titulo;
        }
        set
        {
            _titulo = value;
        }
    }

What can I do here when the user selects?

private void dataGridEmpresa_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {

          --- AQUI! ---

    }

After the change:

<my:EscolherEmpresa TitleValue="{Binding Title,RelativeSource={RelativeSource FindAncestor,AncestorType=Window}, Mode=OneWayToSource}"/>

inserir a descrição da imagem aqui

Where I open Usercontrol:

private void main_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.F5){

            tbTitulo.Text = "ESCOLHER EMPRESA PARA TRABALHAR";

            MainMdiContainer.Children.Clear();
            MainMdiContainer.Children.Add(new MdiChild()
            {
                Margin = new Thickness(-10, -28, 0, 0),
                Width = this.Width - 20,
                Height = this.Height - 113,
                //WindowState = System.Windows.WindowState.Maximized,
                Style = null,
                Content = new Telas.EscolherEmpresa()
            });
        }

    }
  • 1

    Where exactly is your difficulty? It is in how to build the Binding in the shaman, in the implementation of the interface Inotifypropertychanged in the class that has the property Title or is on how to extract, from Grid, the field title in the method dataGridEmpresa_MouseDoubleClick()?

  • I’m not using MVVM @ramaral, I just wanted to take some information from my Datagrid to the application title..

  • Okay, but the information is still too little. You talk about a Textblock, either that information is placed in it or in the attribute Title of Window. If it is in the attribute it is enough, after having this information, to do in the method dataGridEmpresa_MouseDoubleClick() this.Title = varialvelQueTem_a_Infromacao;

  • So, but the attribute Title is in the father window. Already this event Mousedoubleclick is in a Usercontrol son... This is my doubt, how to pass from the son to the Father...

  • In question you do not say that.

  • Sorry @ramaral, I changed the question.

Show 1 more comment

1 answer

2

I haven’t tried it but I think it does what it wants.

In the Usercontrol declare a Dependencyproperty

public string TitleValue
{
    get { return (string)GetValue(TitleValueProperty); }
    set { SetValue(TitleValueProperty, value); }
}

public static readonly DependencyProperty TitleValueProperty =
    DependencyProperty.Register("TitleValue", typeof(string),
                                 typeof(UserControl1));//Nome da classe do UserControl

In the XAML of Window by including the Usercontrol:

<my:UserControl1 TitleValue="{Binding Title,RelativeSource={RelativeSource FindAncestor,AncestorType=Window}, Mode=OneWayToSource}"/>

In the method dataGridEmpresa_MouseDoubleClick():

private void dataGridEmpresa_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{

   string title = //Obtenha o titulo
   TitleValue = title;
}
  • appeared my entire Usercontrol up there on the title in the small space. Did I do something wrong? I posted the image as it stood up there in the post

  • When I am on the main screen (Window Father), I give an F5 and open my Usercontrol. Hence I can select the company to be chosen..

  • Post the code where you open the Usercontrol.

  • I asked the question...

  • So it’s not easy to help, you don’t refer anywhere you’re using to a api external to WPF. I believe it is the WPF.MDI.DLL. I’ve never used it so I can’t help you.

  • I’m using this DLL instead. But anyway I appreciate it then..

Show 1 more comment

Browser other questions tagged

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