This is a migrated thread and some comments may be shown as answers.

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

1 Answer 473 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 21 Apr 2010, 08:29 AM
Hello,
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(); 
        } 
 
        #endregion 
    } 

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

Thanks








1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 26 Apr 2010, 03:25 PM
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,
Hristo
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.
Tags
General Discussions
Asked by
Michele
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Share this question
or