Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all
I have a user Control. Inside user Control I have a datagrid name CustomerGrid fill with customer names. now I have loaded that user control to main window now i want to simply bind selected row or selected customer to textbox in main window.
eg

TextBox Text = "{Binding ElementName=CustomerGrid ,Path=SelectedItem[0]}"

please help me i am Beginner in WPF.
Thanks




This is my Main window.Xaml Code:


<window x:class="NEPFXML.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:CustomerData="clr-namespace:NEPFXML"
Icon="Images\1410369140_network.png"
Title="Shakeel" Height="800" Width="1500" MinWidth="500" MinHeight="500"

x:Name="CustomerForm" Activated="CustomerForm_Activated" WindowStartupLocation="CenterScreen" WindowState="Maximized">

<window.resources>
<customerdata:customerslist x:key="List" xmlns:customerdata="#unknown">

<grid removed="#333">

<grid.rowdefinitions>

<rowdefinition height="50">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="40">
<rowdefinition height="*">

<grid.columndefinitions>
<columndefinition x:name="GridColumn" width="300" minwidth="300" maxwidth="300"> <columndefinition width="150"> <columndefinition width="150"> <columndefinition width="150"> <columndefinition width="150"> <columndefinition width="161"> <columndefinition width="273">
<customerdata:customerslist x:name="CList" grid.row="1" grid.rowspan="9" xmlns:customerdata="#unknown">
<Button Content="Save" Grid.Row="8" Grid.Column="2" Style="{StaticResource StyleButton}" Click="Button_Click" />
<Button Content="Update" Grid.Row="8" Grid.Column="3" Style="{StaticResource StyleButton}" Click="Button_Click" />
<Button Content="Delete" Grid.Row="8" Grid.Column="4" Style="{StaticResource StyleButton}" Click="Button_Click" />
<Button Content="Details" Grid.Row="8" Grid.Column="5" Style="{StaticResource StyleButton}" Click="Button_Click" />

<textblock x:name="FullName" grid.columnspan="3" text="Binding ElementName=Clist,Path=CustomerGrid.SelectedItem[0]" grid.row="0" grid.column="2" fontsize="28" foreground="#E5E4E2" margin="5">



And This is my User Control.XAML Code:


<usercontrol x:class="NEPFXML.CustomersList" xmlns:x="#unknown">
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControl_Loaded">
<grid>
<grid.rowdefinitions>
<rowdefinition>
<rowdefinition>
<rowdefinition>
<rowdefinition>
<rowdefinition>
<rowdefinition>
<rowdefinition>
<rowdefinition>

<grid.columndefinitions>
<columndefinition> <columndefinition> <columndefinition> <columndefinition> <columndefinition> <columndefinition>
<expander grid.row="0" grid.column="0" grid.rowspan="2" grid.columnspan="6" header="Search" foreground="#E5E4E2" isexpanded="False" horizontalalignment="Left" verticalalignment="Top" margin="0,-10,0,0" expanddirection="Down">


<textbox style="{StaticResource StyleTextBox}" x:name="SearchBox" tooltip="Enter Customer Name to Search" width="290" horizontalalignment="Center" verticalalignment="Top" textchanged="SearchBox_TextChanged" margin="5,5,0,5" isreadonly="False">

<datagrid style="{StaticResource StyleDataGrid}" rowstyle="{StaticResource StyleDataGridRow}" cellstyle="{StaticResource StyleDataGridCell}" horizontalalignment="Left" x:name="CustomerGrid" grid.row="1" grid.rowspan="8" grid.columnspan="6">





[Re-posted How to Bind data between two user controls in wpf[^] — SA]
Posted
Updated 25-Feb-15 1:40am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900