Forum guidelines
  • Home
  • »
  • WPF
  • »
  • passing parameters to user control
passing parameters to user control
Posted By nerdfactor on 10 Feb 2010
i would like to pass a parameter to a user control, in order to create a button with a image.

the xaml code should look like this:
<local:ImageButton ImageName="test.png" />

and the object looks something like this:

public string ImageName { get; set; }

public ImageButton() {      
            this.ImageName = ImageName
            this.DataContext = this;       

that has a xaml code like this:
<Grid >
<Image  Source="{Binding ImageName}"/>

and now i want to pass the test.png all the way down, so a can create buttons with different images.

i searched for some time, but i could not find something that i could understand. so i holp someone can help me :)

Re: passing parameters to user control
Posted By Martin Cook on 10 Feb 2010 Hi Nerdfactor,

You can achieve this using a Custom Control and Template Binding.

I've whipped up an example for you.

I hope it helps.


Martin Cook
WPF/Silverlight Developer
Actisoft, UK
Infragistics jQuery Controls


JetBrains ReSharper Ultimate
.NET code analysis, refactorings, navigation, unit testing, code coverage and profiling in Visual Studio, a bonus for C++ devs, bundled at 50% off.