【问题标题】:Setting image from data binding windows mobile c#?从数据绑定windows mobile c#设置图像?
【发布时间】:2013-10-11 07:25:07
【问题描述】:

大家好,我是 Windows Mobile 的新手。我正在使用 LongListSelector。我有我的 Menu.cs 类,它具有以下 setter 和 getter:

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

在我有 LongListSelector 的页面上:

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 的新手。

【问题讨论】:

    标签: windows-phone-7 longlistselector


    【解决方案1】:

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

    您是否将图像“menuHeaderCO3.png”构建操作设置为“内容”?

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

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

    c#

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

    【讨论】:

    • tks 实际上是由于您是否将图像“menuHeaderCO3.png”构建操作设置为“内容”?我已经通过拖放添加了它。我必须做的是添加现有项目。
    猜你喜欢
    • 1970-01-01
    • 2013-01-29
    • 2011-05-31
    • 2023-03-18
    • 1970-01-01
    • 2014-01-06
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多