为什么我在UWP上看不到图标图像?

时间:2017-06-30 07:02:14

标签: uwp xamarin.forms

我正在使用Xamarin.Forms,遵循此tutorial

public MasterPage()
{
    var masterPageItems = new List<MasterPageItem>();
    masterPageItems.Add(new MasterPageItem
    {
        Title = "Contacts",
        IconSource = "contacts.png",
        TargetType = typeof(Pages.Contacts)
    });
    masterPageItems.Add(new MasterPageItem
    {
        Title = "ToDo",
        IconSource = "todo.png",
        TargetType = typeof(Pages.ToDo)
    });
    masterPageItems.Add(new MasterPageItem
    {
        Title = "Reminders",
        IconSource = "reminders.png",
        TargetType = typeof(Pages.Reminder)
    });
    masterPageItems.Add(new MasterPageItem
    {
        Title = "Login",
        IconSource = "reminders.png",
        TargetType = typeof(Pages.Login)
    });
    masterPageItems.Add(new MasterPageItem
    {
        Title = "Sign Up",
        IconSource = "reminders.png",
        TargetType = typeof(Pages.SignUp)
    });

    listView = new ListView
    {
        ItemsSource = masterPageItems,
        ItemTemplate = new DataTemplate(() => {
            var imageCell = new ImageCell();
            imageCell.SetBinding(TextCell.TextProperty, "Title");
            imageCell.SetBinding(ImageCell.ImageSourceProperty, "IconSource");
            return imageCell;
        }),
        VerticalOptions = LayoutOptions.FillAndExpand,
        SeparatorVisibility = SeparatorVisibility.None
    };

    Padding = new Thickness(0, 40, 0, 0);
    Icon = "hamburger.png";
    Title = "Personal Organiser";
    Content = new StackLayout
    {
        VerticalOptions = LayoutOptions.FillAndExpand,
        Children = {
        listView
    }
    };
}

我已将所有icons.png(待办事项,提醒等)放在MyProject.UWP根目录中。

但是当我从Visual Studio(调试模式,x64)运行它时,我无法在Master-Detail页面的导航布局中看到图标。

编辑:我无法在图片的属性中看到BuildAction字段:

enter image description here

编辑2:现在我明白了。您需要&#34;添加现有项目&#34;,而不是在文件夹上放置复制/粘贴图像。

2 个答案:

答案 0 :(得分:2)

BuildAction应设置为Content

答案 1 :(得分:0)

我通过将所有图标添加到UWP的根项目并将构建操作属性设置为内容来解决此问题....