Information in Title - WPF

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 be for the Title of the application ... Is this possible?

The Title attribute is in the parent window. Since this MouseDoubleClick event is in a child UserControl ... This is my doubt, how to pass from child to Father ..

For now I have this TextBlock to be able 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}"/>

WhereIopentheUserControl:

privatevoidmain_KeyDown(objectsender,KeyEventArgse){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()
            });
        }

    }
    
asked by anonymous 22.06.2015 / 22:03

1 answer

2

I did not test but I think this does what you want.

In 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

Window in the UserControl :

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

In the dataGridEmpresa_MouseDoubleClick() method:

private void dataGridEmpresa_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{

   string title = //Obtenha o titulo
   TitleValue = title;
}
    
23.06.2015 / 23:08