如何在 Windows Phone 7 代码隐藏的全景控制中设置图像源?
我正在尝试创建一个简单的全景应用程序,它与您选择在 Visual Studio 中创建全景应用程序时的默认代码非常相似。
我想要的是,我用一个额外的图标图像字段定义自己的 ItemViewModel
,因此新模型有 4 个属性:Icon
、LineOne
、 LineTwo
和 LineThree
。 Icon
是图像或图像文件路径的字符串,LineOne
、LineTwo
和 LineThree
是字符串类型。
默认代码如下:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的
Icon
属性设置为string
并将其绑定到 xaml 中Image
控件的Source
您可以设置图像像这样(不要忘记将图像类型设置为
Content
)Make your
Icon
property asstring
and bind it toSource
ofImage
control in xamlThat you can setup your image like that (don't forget to set type of image as
Content
)