Databind Image in TileVIew

2 posts, 0 answers
  1. Rick Mueller
    Rick Mueller avatar
    103 posts
    Member since:
    Feb 2010

    Posted 27 Aug 2010 Link to this post

    Using the  XmlDataProvider I'm able to bind all the data to the correct elements. Works great in the MainWindow Xaml.  When I Put the TileView control in a page xaml using the same XmlDataProvider I'am able to bind all the elements except the image. I tried using a Imageconverter, but no luck. Is there a trick to get this to bind or I'm missing something?

    Any thoughts?

    Regards,
    Rick

    xmlns:local="clr-namespace:Digital_Kitchen_CdrPrint"
    <local:ImageConverter x:Key="ImageConverter" />

    <Image x:Name="listImg" Source="{Binding XPath=EmpImage, Converter={StaticResource ImageConverter}}"  Stretch="Uniform"/>

     

     

    public class ImageConverter : IValueConverter

     

    {

     

     

    public object Convert(object value, Type targetType, object parameter,

     

    CultureInfo culture)

    {

    String xml =

     

    "<Tables>" + "<Table>" + ((XmlElement)value).InnerXml.ToString() + "</Table>" + "</Tables>";

     

    XmlDocument XDoc =

     

    new XmlDocument();

     

    XDoc.LoadXml(xml);

     

     

    // XmlNodeList oXmlNode = XDoc.GetElementsByTagName("Station");

     

     

     

    //XmlNode node = XDoc.SelectSingleNode("RecipeName");

     

     

    XmlNode oXnode = XDoc.SelectSingleNode(

     

    "Tables/Table/EmpImage");

     

    value = oXnode.LastChild.Value;

    BitmapImage image =

     

    new BitmapImage();

     

     

     

    if (value != null)

     

    {

     

     

    try

     

    {

    image.BeginInit();

    image.CacheOption = BitmapCacheOption.OnLoad;

    image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;

    image.UriSource =

     

    new Uri((string)value, UriKind.Absolute);

     

    image.EndInit();

    }

     

     

    catch

     

    {

    image =

     

    null;

     

    }

    }

     

     

    return image;

     

    }

     

     

    public object ConvertBack(object value, Type targetType, object parameter,

     

    CultureInfo culture)

    {

     

     

    throw new Exception("The method or operation is not implemented.");

     

    }

    }

  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 01 Sep 2010 Link to this post

    Hi Rick,

    Where are the images stored? Do you see any exceptions being thrown in the Output window? If the images are part of the wpf project, what is their Build Action? I've attached a sample project with which I try to mimic your scenario. Have a look at it and let me know if it helps. If you can send me a sample project demonstrating the issue, I'd be better able to assist you.

    All the best,
    Kiril Stanoev
    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
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top