将图像源绑定到不能使用Windows Phone 7的字符串

时间:2013-01-13 03:33:17

标签: wpf silverlight windows-phone-7

我有一个数据库,我存储了我想在我的应用程序中使用的图像地址字符串。我有ClientAuction类,它从DB读取该字符串以及其他东西

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

所有其他绑定都有效,但图像不会显示。我已经尝试了相关地址,硬盘驱动器上的地址,网址但没有显示任何内容。我也尝试过使用Uri和ImageSource或使用BitmapImage但没有结果

 <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>

2 个答案:

答案 0 :(得分:0)

试试这个 -

    <Image>
        <Image.Source>
            <BitmapImage UriSource="{Binding PhotoFilename}" />
        </Image.Source>
    </Image>

答案 1 :(得分:0)

尝试绑定Uri类型的变量而不是string,看看它是否有效。