如何在 Windows Phone 7 代码隐藏的全景控制中设置图像源?

发布于 2024-12-27 05:29:25 字数 955 浏览 3 评论 0原文

我正在尝试创建一个简单的全景应用程序,它与您选择在 Visual Studio 中创建全景应用程序时的默认代码非常相似。

我想要的是,我用一个额外的图标图像字段定义自己的 ItemViewModel ,因此新模型有 4 个属性:IconLineOneLineTwoLineThreeIcon 是图像或图像文件路径的字符串,LineOneLineTwoLineThree 是字符串类型。

默认代码如下:

this.Items.Add(new ItemViewModel() { 
    LineOne = "runtime one", 
    LineTwo = "Maecenas praesent accumsan bibendum",
    LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu" 
});

MainViewModel.cs 类的 LoadData 方法中,我想知道是否可以有类似的东西,但我可以指定我要使用哪个图标图像想在这个方法中设置吗?例如:

this.Items.Add(new NewItemViewModel() { Icon = new Image().Source == "/Images/lineone.jpg" , LineOne = "lineone", LineTwo = "linetwo", LineThree = "linethree" });

谢谢。

I am trying to create a simple Panorama application, which is really similar to the default code when you choose to create a Panorama application in Visual Studio.

What I want is, I define my own ItemViewModel with an extra icon image field, so the new model has 4 properties: Icon, LineOne, LineTwo and LineThree. Icon is an image or an string of path of the image file, LineOne, LineTwo and LineThree are string type.

The default code has something like:

this.Items.Add(new ItemViewModel() { 
    LineOne = "runtime one", 
    LineTwo = "Maecenas praesent accumsan bibendum",
    LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu" 
});

In the LoadData method of MainViewModel.cs class, I am wondering if I can have something like that, but I can specify which icon image I want to set in this method? e.g.:

this.Items.Add(new NewItemViewModel() { Icon = new Image().Source == "/Images/lineone.jpg" , LineOne = "lineone", LineTwo = "linetwo", LineThree = "linethree" });

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2025-01-03 05:29:25

将您的 Icon 属性设置为 string 并将其绑定到 xaml 中 Image 控件的 Source

 <Image ImageSource={Binding Icon} ... />

您可以设置图像像这样(不要忘记将图像类型设置为 Content

 this.Items.Add(new NewItemViewModel() { Icon = "/Images/lineone.jpg" , LineOne = "lineone", LineTwo = "linetwo", LineThree = "linethree" })

Make your Icon property as string and bind it to Source of Image control in xaml

 <Image ImageSource={Binding Icon} ... />

That you can setup your image like that (don't forget to set type of image as Content)

 this.Items.Add(new NewItemViewModel() { Icon = "/Images/lineone.jpg" , LineOne = "lineone", LineTwo = "linetwo", LineThree = "linethree" })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文