从数据绑定窗口移动 C# 设置图像



大家好,我是Windows Mobile的新手。我正在使用一个长名单选择器。我有我的类菜单.cs其中有以下设置器和获取器:

   public Uri Picture
    {
        get { return picture; }
        set
        {
            if (value != picture)
            {
                picture = value;
                NotifyDataHasChanged("Picture");
            }
        }
    }

在我的页面上,我有我的长名单选择器:

this.menu.Add(new Menu() { Name = "ccc", Picture = new Uri("/Assets/GFX/menuHeaderCO3.png", UriKind.Relative) });
            longListMenuSlide.ItemsSource = menu;

和 XAML:

<phone:LongListSelector x:Name="longListMenuSlide" HorizontalAlignment="Left" Height="594" Margin="0,102,0,0" VerticalAlignment="Top" Width="370" Grid.RowSpan="2">
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,0">
                            <Image Source="{Binding Picture}" Height="78" Width="370" 
                               HorizontalAlignment="Left" Stretch="UniformToFill"/>

                            </StackPanel>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>

它不起作用..我看不到任何图像。但是如果我对图像源进行硬编码:

<Image Source="/Assets/GFX/menuCO5.png" Height="78" Width="370" 
                               HorizontalAlignment="Left" Stretch="UniformToFill"/>

这行得通。有什么帮助吗?我是 Windows Mobile 的新手。

仅供参考:将图片属性设置为字符串也可以,图像控件绑定应该处理这个问题。

是否已将映像"menuHeaderCO3.png"生成操作设置为"内容"?

如果这不起作用,请在控件上设置图像失败事件以查看调试得到的内容,并将消息附加到问题中

<Image ImageFailed="ImageFailed" Source="{Binding Picture}" />

C#

 private void ImageFailed(object sender, ExceptionRoutedEventArgs e)
    {
        MessageBox.Show(e.ErrorException.Message);
    }

最新更新