Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:41:34+00:00 2026-05-26T13:41:34+00:00

I’m using an xml as source of my application via binding. in the xml

  • 0

I’m using an xml as source of my application via binding. in the xml there is a list of folders and a path for a sample image for each folder. The folder list is binded to listbox, and another display is binded to the selected item of the listbox, which is an item of the xml list (type XmlNode). I added the opertunity to add and remove items using the XmlDocument which was copied from the xml by the XmlProvider and save it to the source file.

The problem begins when the source list is empty, either at the application load time, or after removing all of the items. at this point all of the binded values of the display are null. I solved all of the bindings with the binding’s TargetNullValue property, exept the canvas background imagebrush image_source property which shows nothing.

I tried to use a converter, but when I debuged it I saw something weird. if there were items in the list the converter returned what is should and the image was displayed, but if the list was empty, the converter returned what it should and no image was shown!
plz help me.

Code:

XML:

  <Folders>
    <Folder Id="1">
      <Path>folder3\1</Path>
      <SampleImage>C:\images\2011-09-22\site3\1\6.jpg</SampleImage>
    </Folder>
  </Folders>

XAML:

    <Canvas.Background>
      <ImageBrush x:Name="SampleImage" Stretch="Uniform" >
        <ImageBrush.ImageSource>
          <MultiBinding Converter="{StaticResource ImageConverter}" Mode="OneWay">
            <Binding XPath="./SampleImage" />
            <Binding Source="C:\images\SampleImages\no_image.jpg"/>
          </MultiBinding>
        </ImageBrush.ImageSource>
      </ImageBrush>
   </Canvas.Background>

c#:

public class ImageConverter : IMultiValueConverter
{
    public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        ImageSourceConverter imageConverter = new ImageSourceConverter();
        bool bool1=value[0].Equals(DependencyProperty.UnsetValue);
        if (value[0] != null &&!bool1) //if the source isn't null
        {
             //this works fine
             return imageConverter.ConvertFromString(value[0].ToString());
        }
        //here the converter returns the right object but the alternate image isn't shown and the background left blank
        return imageConverter.ConvertFromString(value[1].ToString());

        //here too the converter returns the right object but the alternate image isn't shown and the background left blank
        //return imageConverter.ConvertFromString(@"C:\images\SampleImages\no_image.jpg");

    }


    public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return null;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:41:35+00:00Added an answer on May 26, 2026 at 1:41 pm

    You call a method on one of the values before checking it for null:

    bool bool1=value[0].Equals(DependencyProperty.UnsetValue);
    if (value[0] != null &&!bool1)
    

    This is just one possible source for errors. Of course the file paths need to be correct as well as Kent Boogaart already pointed out. Further: “this don’t work” is not helpful, if you want good answers provide as much information as possible. i.e. what exactly happened & what you expected and how those expectations were not met.


    The converter could be compressed to the following by the way:

    string path = (value[0] is string && value[0] != null) ?
        (string)value[0] : (string)value[1];
    return new ImageSourceConverter().ConvertFromString(path);
    

    Quite possibly still not ideal but less cluttered.


    Edit: As the code works for me i suspect that the layout is to blame, if there are no items your control possibly does not take up any space anymore, hence making the image invisible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.