I am just starting out with Silverlight (2 RC0) and it doesn't seem to work. I want to create a custom control for a simple image.
My xaml for the user control is as follows:
<Button> <Button.Template> <ControlTemplate> <Image Source="{TemplateBinding ImageSource}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" /> </ControlTemplate> </Button.Template> </Button>
The code is as follows:
public partial class ImageButtonUserControl : UserControl { public ImageButtonUserControl() { InitializeComponent(); } public Image Source { get { return base.GetValue(SourceProperty) as Image; } set { base.SetValue(SourceProperty, value); } } public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("SourceProperty", typeof(Image), typeof(ImageButtonUserControl),null); }
I want to be able to dynamically create ImageButtons and add them to a container, for example WrapPanel: Suppose we already have an image named "image":
ImageButtonUserControl imageButton = new ImageButtonUserControl(); imageButton.Source = image; this.thumbnailStackPanel.Children.Add(imageButton);
What do I need to do to display the image? I suppose I need to do something with the DataContext, but I'm not quite sure what and where.
Thanks for any help
silverlight user-controls
ckarbass
source share