Click here to Skip to main content
11,704,044 members (67,193 online)
Rate this: bad
good
Please Sign up or sign in to vote.
What's wrong with this picture?

http://gilgameshcontrite.com/BadImage.jpg[^]

Instead of displaying a nice picture of a prehistoric plant, the string of the location of the bitmap is being displayed!

Here's the XAML (snippet):

<DataTemplate x:Key="YoungPicCell">
    <StackPanel Orientation="Horizontal">
        <Image Height="200" Width="200" Stretch="None"  Source="{Binding YoungPicBmp}"    />
    </StackPanel>
</DataTemplate>


The filenames (and other data) are loaded at runtime from an XML file.

Here is the relevant code:

public WindowViewModel _wvm;
 
  public PlantDisplay()
  {
      InitializeComponent();
      _wvm = new WindowViewModel();
      this.DataContext = _wvm;
  }
 
  public class LVData
  {
      public string Name { get; set; }
      public string YoungPic { get; set; }
      public BitmapSource YoungPicBmp { get { return new BitmapImage(new Uri("{YoungPic}")); } }
      public string MediumPic { get; set; }
      public BitmapSource MediumPicBmp { get { return new BitmapImage(new Uri("{MediumPic}")); } }
      public string AdultPic { get; set; }
      public BitmapSource AdultPicBmp { get { return new BitmapImage(new Uri("{AdultPic}")); } }
      public bool SaltWater { get; set; }
      public bool FreshWater { get; set; }
      public bool Grasslands { get; set; }
      public bool Swamp { get; set; }
      public bool TropicalForest { get; set; }
      public bool Forest { get; set; }
      public bool ForestEdge { get; set; }
      public bool Sand { get; set; }
      public bool Coastal { get; set; }
      public bool RiverBorder { get; set; }
      public bool LakeBorder { get; set; }
      public bool Floodplain { get; set; }
  }
 

  public class WindowViewModel : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged;
      //called when a property is changed
      protected void RaisePropertyChanged(string PropertyName)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
          }
      }
 
      private ObservableCollection<LVData> _plantList = new ObservableCollection<LVData>();
      public ObservableCollection<LVData> lsvData
      {
          get { return _plantList; }
          set { _plantList = value; RaisePropertyChanged("lsvData"); }
      }
 
      public void PopulateDataFromXML(string filename)
      {
 
          XDocument loaded = XDocument.Load(filename);
 
          var Plants = from x in loaded.Descendants("Plants")
                        select new
                        {
                            Name = x.Descendants("Name").First().Value,
                            YoungPic = x.Descendants("YoungPic").First().Value,
                            MediumPic = x.Descendants("MediumPic").First().Value,
                            AdultPic = x.Descendants("AdultPic").First().Value,
                            SaltWater = x.Descendants("SaltWater").First().Value,
                            FreshWater = x.Descendants("FreshWater").First().Value,
                            Grasslands = x.Descendants("Grasslands").First().Value,
                            Swamp = x.Descendants("Swamp").First().Value,
                            TropicalForest = x.Descendants("TropicalForest").First().Value,
                            Forest = x.Descendants("Forest").First().Value,
                            ForestEdge = x.Descendants("ForestEdge").First().Value,
                            Sand = x.Descendants("Sand").First().Value,
                            Coastal = x.Descendants("Coastal").First().Value,
                            RiverBorder = x.Descendants("RiverBorder").First().Value,
                            LakeBorder = x.Descendants("LakeBorder").First().Value,
                            Floodplain = x.Descendants("Floodplain").First().Value
                        };
 

          foreach (var _plant in Plants)
          {
              _plantList.Add(new LVData {
                  Name = _plant.Name,
                  YoungPic = _plant.YoungPic,
                  MediumPic = _plant.MediumPic,
                  AdultPic = _plant.AdultPic,
                  SaltWater = Convert.ToBoolean(_plant.SaltWater),
                  FreshWater = Convert.ToBoolean(_plant.FreshWater),
                  Grasslands = Convert.ToBoolean(_plant.Grasslands),
                  Swamp = Convert.ToBoolean(_plant.Swamp),
                  TropicalForest = Convert.ToBoolean(_plant.TropicalForest),
                  Forest = Convert.ToBoolean(_plant.Forest),
                  Sand = Convert.ToBoolean(_plant.Sand),
                  Coastal = Convert.ToBoolean(_plant.Coastal),
                  RiverBorder = Convert.ToBoolean(_plant.RiverBorder),
                  LakeBorder = Convert.ToBoolean(_plant.LakeBorder),
                  Floodplain = Convert.ToBoolean(_plant.Floodplain)
 
              });
 
          }
          RaisePropertyChanged("lsvData");
      }
}
Posted 13-Jun-13 7:05am
Zetar379
Edited 13-Jun-13 7:07am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can use converter for the same .Please have a look of following
 
<Window
xmlns:local1="clr-namespace:**********">
</window>




create this class under the same namespace as ur mainclass have
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 530
1 OriginalGriff 510
2 Sergey Alexandrovich Kryukov 421
3 Andy Lanng 294
4 F-ES Sitecore 220
0 OriginalGriff 8,744
1 Sergey Alexandrovich Kryukov 7,747
2 CPallini 5,107
3 Maciej Los 4,716
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100