locked
how to set text for user control textblock? RRS feed

  • Question

  • i ve one usercontrol in that i ve one textblock..

    and i ve added that user control in my mainpage.xmal

    now i want to set text of that user control text block from main page.

    Thanks in advance..

    Regards,

    karthik.v

    Friday, April 20, 2012 3:48 AM

Answers

  • Try this,

    1. Create a public property in your user control.

    2. In the set of this user property set the the textblock.text = value.

    3. In your main page you should be able to access your user control (if you have added the same through XAML make sure you have the x:name ="<usercontrolname>" set)

    4. In your mainPage.xaml.cs/vb you should be able to set this property you created in step 2.

    Friday, April 20, 2012 1:08 PM

All replies

  • Try this,

    1. Create a public property in your user control.

    2. In the set of this user property set the the textblock.text = value.

    3. In your main page you should be able to access your user control (if you have added the same through XAML make sure you have the x:name ="<usercontrolname>" set)

    4. In your mainPage.xaml.cs/vb you should be able to set this property you created in step 2.

    Friday, April 20, 2012 1:08 PM
  • If you wanna bind to the property in your user control then you have to create a DependencyPropertry, http://msdn.microsoft.com/en-us/library/cc221408(v=VS.95).aspx

    Friday, April 20, 2012 4:56 PM
  • hi,

    You can make a property in your main page and set the value of ur text through this property, then you have to bind the usercontrol with that property in xaml of usercontrol.

    <TextBox Height="auto" MaxLength="2000" Text="{BindingPath=Test.description,Mode=TwoWay,UpdateSourceTrigger=Default,ValidatesOnExceptions=True,NotifyOnValidationError=True}" HorizontalAlignment="Left" HorizontalContentAlignment="Left" Name="txtCaseDetails" TextWrapping="Wrap" VerticalAlignment="Top" MinWidth="425" Width="425" MinHeight="100" Grid.Row="1" Grid.Column="1" Grid.RowSpan="4" Grid.ColumnSpan="4" Margin="5,5"></TextBox>

    private CaseClass test;

    public CaseClass Test

    {

    get

    {

    return this.test;

    }

    private set

    {

    this.test = value;

    this.RaisePropertyChanged("Test");

    }

    }

     

    Monday, April 23, 2012 12:40 AM