Issue binding Image Source dependency property

Posted by Archana R on Stack Overflow See other posts from Stack Overflow or by Archana R
Published on 2010-04-28T10:04:35Z Indexed on 2010/04/28 10:13 UTC
Read the original article Hit count: 308

Hello,

I have created a custom control for ImageButton as

<Style TargetType="{x:Type Button}">
     <Setter Property="Template">
           <Setter.Value>
              <ControlTemplate TargetType="{x:Type Local:ImageButton}">
               <StackPanel Height="Auto" Orientation="Horizontal">
                 <Image Margin="0,0,3,0" Source="{Binding ImageSource}" />
                 <TextBlock Text="{TemplateBinding Content}" /> 
               </StackPanel>
              </ControlTemplate>
           </Setter.Value>
     </Setter>
</Style>

ImageButton class looks like

public class ImageButton : Button
    {
        public ImageButton() : base() { }

        public ImageSource ImageSource
        {
            get { return base.GetValue(ImageSourceProperty) as ImageSource; }
            set { base.SetValue(ImageSourceProperty, value); }
        }
        public static readonly DependencyProperty ImageSourceProperty =
          DependencyProperty.Register("Source", typeof(ImageSource), typeof(ImageButton));
    }

However I'm not able to bind the ImageSource to the image as: (This code is in UI Folder and image is in Resource folder)

  <Local:ImageButton x:Name="buttonBrowse1" Width="100" Margin="10,0,10,0"
 Content="Browse ..." ImageSource="../Resources/BrowseFolder.bmp"/>

But if i take a simple image it gets displayed if same source is specified. Can anyone tell me what shall be done?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about custom-controls