Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have two user controls in a WPF application. I want to change the "text of the Textbox control by clicking a button which is present in another user control.

Please help me out.
Posted
Updated 8-Dec-11 0:42am
v3
Comments
Slacker007 8-Dec-11 6:42am    
Edited: tags and formatting.

1 solution

You can use datagrid template as:
XML
<DataGridTemplateColumn Header="Command">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Button Name="cmdCommand" Click="{Binding Command}"
                    Content="Command"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn
 
Share this answer
 
Comments
Member 7962316 8-Dec-11 10:01am    
my requirement when i click button in firtuser control it should display text in another user control text box.My code is as followes please tell wat is wrong:

This is my main page
<Page x:Class="test.Page2"
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"
xmlns:ucl="clr-namespace:test"
Title="Page2">
<grid>
<ucl:usercontrol1>
<ucl:usercontrol2 loaded="UserControl2_Loaded">

</Page>

my UserControl1.xaml
<usercontrol x:class="test.UserControl1"
="" 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">
<grid>
<textbox height="23" horizontalalignment="Left" margin="120,60,0,0" x:name="textBox1" text="{Binding Path=name}" verticalalignment="Top" width="120">



my UserControl.xaml.cs

namespace test
{
///
/// Interaction logic for UserControl1.xaml
///

public partial class UserControl1 : UserControl,INotifyPropertyChanged
{
public UserControl1()
{
InitializeComponent();
}
public event PropertyChangedEventHandler PropertyChanged;
private string n;
public string name
{
get { return n; }
set { n = value;
OnPropertyChanged("name");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
}

my Usercontrol2.xaml

<usercontrol x:class="test.UserControl2"
="" 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">
<grid>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="42,154,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />



MY UserControl2.xaml.cs

namespace test
{
///
/// Interaction logic for UserControl2.xaml
///

public partial class UserControl2 : UserControl
{
public UserControl2()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
UserControl1 obj = new UserControl1();
obj.name = "dinakar";
}
}
}


please help...

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