none
How to Pass The vale From usercontrol to another control

    Question

  • HI ALL,

    how to get the value in the siverlight from main page to usercontrol

    Currently i have many tab in each tab have differnect user control

     <Canvas Height="635" Name="canvas1" Width="1000">
                        <sdk:TabControl Canvas.Left="-2" Canvas.Top="-3" Height="677" Name="tabControl1" Width="930" AllowDrop="True" SelectionChanged="tabControl1_SelectionChanged"
                                        IsEnabled="False">
                            <sdk:TabItem Header="Company0" Name="tabItem0" Visibility="Collapsed">
                                <Grid>
                                </Grid>
                            </sdk:TabItem>
                            <sdk:TabItem Header="Company" Name="tabItem1">
                                <Canvas>
                                    <local:CompanyUCtrl Canvas.Left="0" HorizontalAlignment="Left"></local:CompanyUCtrl>
                                    <!--<local:CompanyScreen/>-->
                                </Canvas>
                            </sdk:TabItem>
                            <sdk:TabItem Header="Earnings" Name="tabItem3" >
                                <Grid />
                            </sdk:TabItem>
     </sdk:TabControl>

    UserControl.CS

    public  int DealID { get; set; }

            public CompanyUCtrl()
            {
                InitializeComponent();
               
            }
     private void UserControl_Loaded(object sender, RoutedEventArgs e)
            {
                int asd = DealID;
            }

    MainPage.cs
     private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
    UserControl cmp = new UserControl ();
                cmp.DealIdRow = dealId;
    }



    So in the mainpage.cs have DEAL ID i have pass the DealId to UserControl so that i can easily get the data from service

    can any one help me how to pass the data from Mainpage to controlpage


    PLs is't very urgent

    thanks in Advances

    Friday, May 11, 2012 8:02 AM

Answers

  • Hi. If there is not any relation with both then You may use event handlers or action for this purpose by creating your eventsArgs class.
    Saturday, May 12, 2012 4:12 AM
  • UserControl cmp = new UserControl ();
                cmp.DealIdRow = dealId;

    Hi UserControl class is the base class all usercontrol. So there is no DealIRow in the UserControl.

    As your mentioned that your question is How to Pass The vale From usercontrol to another control.

    I suggest you to change the DealId Property to DependencyProperty.

    Such as

            
    public int DealId
            {
                get { return (int)GetValue(DealIdProperty); }
                set { SetValue(DealIdProperty, value); }
            }
    
            // Using a DependencyProperty as the backing store for DealId.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty DealIdProperty =
                DependencyProperty.Register("DealId", typeof(int), typeof(CompanyUCtrl), new PropertyMetadata(0));
    

    Then you can bind any properties to DealId as you wish.Hope helpful.

    Monday, May 14, 2012 12:56 AM

All replies

  • you can pass the value from main page to user control by creating property in main page and bind that property to the property of user control.

    Please mark as Answer, if it helps you .

    Friday, May 11, 2012 9:07 AM
  • Hi. If there is not any relation with both then You may use event handlers or action for this purpose by creating your eventsArgs class.
    Saturday, May 12, 2012 4:12 AM
  • UserControl cmp = new UserControl ();
                cmp.DealIdRow = dealId;

    Hi UserControl class is the base class all usercontrol. So there is no DealIRow in the UserControl.

    As your mentioned that your question is How to Pass The vale From usercontrol to another control.

    I suggest you to change the DealId Property to DependencyProperty.

    Such as

            
    public int DealId
            {
                get { return (int)GetValue(DealIdProperty); }
                set { SetValue(DealIdProperty, value); }
            }
    
            // Using a DependencyProperty as the backing store for DealId.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty DealIdProperty =
                DependencyProperty.Register("DealId", typeof(int), typeof(CompanyUCtrl), new PropertyMetadata(0));
    

    Then you can bind any properties to DealId as you wish.Hope helpful.

    Monday, May 14, 2012 12:56 AM