How Do I set a Grid.Background ImageBrush with binding?

2 posts, 0 answers
  1. Michele
    Michele avatar
    426 posts
    Member since:
    Jun 2009

    Posted 21 Apr 2010 Link to this post

    I've got a question, I've got some SL project of a unique solution that shares the most of images, I wished to bind the Grid.BackGround.ImageBrush using a {Binding}, but I got a AG_E_PARSER_BAD_PROPERTY_VALUE , the only way I've found is to set the ImageSource to a fake image, then adding the ImageFailed event and here set the ImageSource

    For the classic images i use :
    <Image Source="{Binding ICO_SEARCH, Converter={StaticResource ImageLocator}}" Height="20" Width="20" />

    where ImageLocator is :

     public class ImageLocatorConverter : IValueConverter 
            #region IValueConverter Members 
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
                string imageName = string.Format("./Images/{0}", value); 
                          Uri baseUri = ProxyFactory.GetUriFromLocalPath(); 
                Uri uri = new Uri(baseUri, imageName); 
                BitmapImage img = new BitmapImage(uri); 
                return img; 
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
                throw new NotImplementedException(); 

    and ImageRepository is :

      public class ImageRepository 
            public string IMG_MIFID { get { return "mifid.png"; } private set { } } 
            public string IMG_DISALL { get { return "forex.jpg"; } private set { } } 
            public string IMG_MAP { get { return "Mondoaparte.jpg"; } private set { } } 
            public string IMG_UTILITY { get { return "utility.png"; } private set { } } 
            public string ICO_XLS { get { return "icon_xls.jpg"; } private set { } } 
            public string ICO_INSERT { get { return "insert.png"; } private set { } } 
            public string ICO_SEARCH { get { return "search.png"; } private set { } } 
            public string ICO_DELETE { get { return "delete_16x16.png"; } private set { } } 
            public string IMG_BACKGROUND { get { return "background.jpg"; } private set { } } 
            public static string PROVA { get { return "background.jpg"; } private set { } } 

    Is it best to have a DO class that contains all the images or can I achieve this in that way? I wish to have the SL application to point to http://<mysitename>/images/{picture} without having to hardcode the mysite name in XAML


  2. Hristo
    Hristo avatar
    832 posts

    Posted 26 Apr 2010 Link to this post

    Hi Paolo,

    It is possible to bind Grid.Background property.
    I've attached project that you can use as reference.

    Let us know if you need more information.

    All the best,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top