Click here to Skip to main content
15,920,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Goal:
The input data that is located inside of the textbox(usercontrol_menu.xaml) shall be transferred and then to be used and displayed in the label inside of usercontrol_number1.xaml. The transportation of the input data will be executed when you have pressed the button "enter" or clicked on the button "Send" inside of usercontrol_menu.xaml.

Problem:
Do you have a concrete example combined on my source code in order to achieve the goal?

Information:
- MainWindows.xaml is located in a separated project.

http://bit.ly/1ockD7L

XML
XAML

-- MainWindow.xaml

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:usercontrol_menu="clr-namespace:usercontrol_menu;assembly=usercontrol_menu" xmlns:usercontrol_number1="clr-namespace:usercontrol_number1;assembly=usercontrol_number1" x:Class="MainWindows.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>

        <usercontrol_menu:UserControl1 HorizontalAlignment="Left" VerticalAlignment="Top" Height="124" Width="434" Margin="24,28,0,0"/>
        <usercontrol_number1:UserControl1 HorizontalAlignment="Left" Margin="24,176,0,0" VerticalAlignment="Top" Height="115" Width="434"/>

    </Grid>
</Window>



-- usercontrol_menu         UserControl1.xaml

<UserControl x:Class="usercontrol_menu.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 removed="#FFF3CBCB">
        <Button x:Name="btn_send" Content="Send" HorizontalAlignment="Left" Margin="99,100,0,0" VerticalAlignment="Top" Width="75"/>
        <TextBox x:Name="txt_input" HorizontalAlignment="Left" Height="23" Margin="54,57,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
    </Grid>
</UserControl>



-- usercontrol_number1         UserControl1.xaml

<UserControl x:Class="usercontrol_number1.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 removed="#FFFF9D9D">
        <Label x:Name="lbl_text" Content="Text" HorizontalAlignment="Left" Margin="31,44,0,0" VerticalAlignment="Top"/>
    </Grid>
</UserControl>
Posted

1 solution

The user controls shouldn't know about each other: so the one with the button signals an event which is handled by the form, which passes the into to the second control.

Exactly the same principle as this: Transferring information between two forms, Part 3: Child to Child[^] but with controls instead of child forms.
 
Share this answer
 

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