按钮后,确定图像源单击Windows 10 UWP,XAML C# [英] Define image source after button click Windows 10 UWP, XAML C#

查看:335
本文介绍了按钮后,确定图像源单击Windows 10 UWP,XAML C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的开发人员努力学习,以开发用于Windows 10 UWP,我一直从基础挣扎天。我只是想弄清楚如何使用C#改为XAML性能,特别是我想改变图像的来源,这样点击按钮将改变显示的图像。我已经习惯了的JavaScript和jQuery这使得这个过程绝对无痛的($(#elementID),ATTR(SRC,图像/ NameOfFile.PNG);)。我怎么了UWP应用程序做到这一点?好像数据绑定相似,但我有很多困难理解它,无法想象这样做这么简单的东西必须是如此困难。你能不能帮我这个?谢谢!

I'm a new developer trying to learn to develop for Windows 10 UWP and I've been struggling with the basics for days. I'm just trying to figure out how to change XAML properties using C#, in particular I'd like to change the source of an image so that clicking a button will change the image displayed. I'm used to javascript and jQuery which make this process absolutely painless ($("#elementID").attr("src", "Images/NameOfFile.PNG");). How do I do this for a UWP app? It seems like data binding is similar but I'm having a lot of difficulty understanding it and can't imagine that doing something so simple would have to be so difficult. Can you help me with this? Thanks!

推荐答案

最简单的方式(无数据绑定)是直接访问Image控件代码后面。给该控件的名称

The most simple way (without data binding) is to directly access the Image control in code behind. Give the control a name

<Image x:Name="image"/>

和在代码中设置其Source属性后面,例如在按钮单击处理程序

and set its Source property in code behind, e.g. in a Button Click handler

image.Source = new BitmapImage(new Uri("ms-appx:///Images/NameOfFile.png"));



其中, NameOfFile.png 必须加。一个文件夹命名为图片在Visual Studio项目

where NameOfFile.png must be added to a folder named Images in your Visual Studio project.

请参阅的类乌里有关 MS-APPX细节:// 方案。

这篇关于按钮后,确定图像源单击Windows 10 UWP,XAML C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆