0

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

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

2 回答 2

0

尝试这个 -

    <Image>
        <Image.Source>
            <BitmapImage UriSource="{Binding PhotoFilename}" />
        </Image.Source>
    </Image>
于 2013-01-13T07:44:08.880 回答
0

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

于 2014-09-11T14:02:57.727 回答