How to Binding an element that was inherited from a User Control?

Asked

Viewed 72 times

1

I set up a User Control that will be a screen model for me to implement other screens and avoid repetition of layout components. It contains a txbPsearch Textbox.

<UserControl x:Class="SistemaComercial.Presentation.WPF.Views.Lists.UserConstrols.ucListPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:SistemaComercial.Presentation.WPF.Views.Lists.UserConstrols"
             xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
             mc:Ignorable="d" 
             d:DesignHeight="768" d:DesignWidth="1024">
    <Grid>         
    <Grid Name="Principal">
        <Grid.RowDefinitions>
            <RowDefinition Height="70"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>

        <Border Background="#FF444444" Grid.Row="0">
            <DockPanel VerticalAlignment="Stretch">
                <Canvas>
                    <TextBox controls:TextBoxHelper.ClearTextButton="True" Name="txtPesquisar" Width="376" Canvas.Top="20" Canvas.Left="525" FontSize="18" DockPanel.Dock="Right" controls:TextBoxHelper.Watermark="Pesquisar informações do cliente">
                    </TextBox>                        
                </Canvas>
            </DockPanel>
        </Border>
        <Border Grid.Row="2"/>
    </Grid>
</Grid>

In my Page of customers I made the link with User Control, but then hit the question: How do I give a Binding on txtPind.text that’s on my page, if it’s just a component inherited from User control?

<Page x:Class="SistemaComercial.Presentation.WPF.Views.Lists.ClienteListPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
      xmlns:uc="clr-namespace:SistemaComercial.Presentation.WPF.Views.Lists.UserConstrols"
      xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
      xmlns:local="clr-namespace:SistemaComercial.Presentation.WPF.Views.Lists"
      xmlns:viewModels="clr-namespace:SistemaComercial.Presentation.WPF.ViewModels"
      mc:Ignorable="d" 
      d:DesignHeight="768" d:DesignWidth="1024"
      Title="ClienteListPage">

    <Grid>
        <uc:ucListPage (txtPesquisar.text = {Binding Path=Pesquisa}")/>
    </Grid>

</Page>

1 answer

1


  • Thanks for the vnbrs tip, but what if in my Usercontrol I do not implement anything, that is, create only the components in which I will inherit and implement in a window. How I would access a textbox inherited from Usercontrol in my Window?

Browser other questions tagged

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