Sunday, January 13, 2013

Binding Image source to a string not working Windows Phone 7

Binding Image source to a string not working Windows Phone 7

I have a database where I store strings of addresses of images which I wanna use in my app. I have ClientAuction Class which reads that string from the DB along with other things

public class ClientAuction : INotifyPropertyChanged {       private string photoFileName;      public string PhotoFilename     {         set         {             if (photoFilename != value)             {                 photoFilename = value;                 OnPropertyChanged("PhotoFilename");             }         }         get         {             return photoFilename;         }     } } 

All the other bindings are working but the images just won't show. I've tried relative addresses, addresses on my hard drive, web addresses but nothing shows up. I've also tried using Uri and ImageSource or using a BitmapImage in but no result

 <Grid Name="AllAuctionsContentPanel" DataContext="{Binding Source={StaticResource presenter}}">                 <ScrollViewer>                     <ListBox Name="AllItems" ItemsSource="{Binding Auctions}"  Height="750" SelectionChanged="Items_SelectionChanged">                         <ListBox.ItemTemplate>                             <DataTemplate>                                 <Border BorderBrush="{StaticResource PhoneAccentBrush}"                                  Width="450"                                 BorderThickness="1"                                 CornerRadius="12"                                 Margin="2">                                     <Grid>                                         <Grid.RowDefinitions>                                             <RowDefinition Height="*" />                                             <RowDefinition Height="*" />                                         </Grid.RowDefinitions>                                          <Grid.ColumnDefinitions>                                             <ColumnDefinition Width="*" />                                             <ColumnDefinition Width="*" />                                         </Grid.ColumnDefinitions>                                         <Image Grid.Row="0" Grid.Column="0"                                         Source="{Binding PhotoFileName}"                                        Height="128"                                        Width="128"                                        Margin="10">                                          </Image>                                          <ContentControl Grid.Row="0" Grid.Column="1"                                                  HorizontalAlignment="Left"                                                 VerticalAlignment="Center">                                             <StackPanel >                                                 <StackPanel Orientation="Horizontal">                                                     <TextBlock Text="Item Name: "></TextBlock>                                                     <TextBlock Text="{Binding ItemName}"></TextBlock>                                                 </StackPanel>                                                 <StackPanel Orientation="Horizontal">                                                     <TextBlock Text="Starting Bid: "></TextBlock>                                                     <TextBlock Text="{Binding StartingBid}"></TextBlock>                                                 </StackPanel>                                                 <StackPanel Orientation="Horizontal">                                                     <TextBlock Text="End Time: "></TextBlock>                                                     <TextBlock Text="{Binding EndTime}"></TextBlock>                                                 </StackPanel>                                             </StackPanel>                                         </ContentControl>                                     </Grid>                                 </Border>                             </DataTemplate>                         </ListBox.ItemTemplate>                     </ListBox>                 </ScrollViewer>             </Grid> 

Answers & Comments...

Answer: 1

Try this -

    <Image>         <Image.Source>             <BitmapImage UriSource="{Binding PhotoFilename}" />         </Image.Source>     </Image> 
by : RV1987http://stackoverflow.com/users/632337




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog