User Control with Dynamic Content RRS feed

  • Question

  • I am trying to create a user control made up of an image and two text blocks. I want to be able to drop this user control into a project and change the image source and the text for the text blocks. How would I go about doing this strictly in XAML (no code-behind)?

    • Edited by Todd Pierpoint Friday, February 29, 2008 10:17 PM changed verbiage
    Friday, February 29, 2008 10:15 PM

All replies

  • Hi Todd,

    You should expose properties in your UserControl that represent the Image (of type ImageSource) and the two text blocks (hence of type String). You can then set these anywhere where you instantiate the UserControl.

    In your UserControl xaml, you can then utilize these properties like:

    <TextBlock Text="{Binding ElementName="UserControl", Path=MyStringProperty}" />

    My apologies if I messed up the XAML, but you can author the XAML in Blend :).
    Friday, February 29, 2008 11:58 PM
  • Hi, Unni. Please pardon my ignorance, but would you please give me an example of how to expose properties for images and text blocks in a user control?



    Tuesday, March 11, 2008 6:51 PM
  • Hi Todd,

    Here is an example: http://blogs.msdn.com/expression/articles/525441.aspx

    Tuesday, March 11, 2008 7:04 PM