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!
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"/>
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"));
where NameOfFile.png must be added to a folder named Images in your Visual Studio project.
See class Uri for details about the ms-appx:// scheme.
Related
I am trying to develop a wpf custom control component, where in i need to browse files from my local machine through property and need to select the file at design time. To do this we would need a button (...) and textbox to to hold the file path. File browsing and selection is done at design time and in run time the file should be displayed on the WPF form. I am able to achieve this Winforms (using UItype Editor ) however i am not able to do this in WPF as there is UItypeeditor is not available in wpf.
I [1]: https://i.stack.imgur.com/Lam5a.png attached One Sample Property Image, Expected output in design time of Custom control properties for your quick reference.
I am a new bee in WPF, request you to help with a sample code or link.
Thank you for helping me in Advance.
Please check out might help you this..
Hi Please have a look at this link. it has a sample project with implementation.
I am working on a WPF application where we have to automate testing.
This work fine for many components but we struggle to check a summary page where we use TextBlock to display our data.
The WPF TextBlock is not found by the HP tool. Thus we cannot check the values that we display.
We tried the following solutions but without success:
Change x:Name in Name (not the best idea right, but we tried all!)
AutomationProperties.AutomationId on the TextBloc
AutomationProperties.Name
Make the TextBlock focusable
The solution presented here: WPF Tutorial Solution
None of them Worked and we are currently blocked.
Has anyone experience with this? Is there a clean solution to solve this issue?
What we need: access TextBlock content, in particular Text from HP UFT Tool.
Here the correct answer:-
1) Open UFT
2) Open your wfp ".exe" file in UFT and run. (YourwpfFile.exe)
3) then you can able to identify the WFP window using object spy.
How can I open the TimePicker to select new time but from C#? Not by tapping the control.
Is there any simple way to do that?
I had the same problem once. I solved it by forking the Windows Phone Toolkit and making the OpenPickerPage of the control public.
(I assume you mean the Windows Phone Toolkit TimePicker control here.)
From reading the source code of the DateTimePickerBase, it would seem not. Opening the picker page is done by the OpenPickerPage() method, which is private, and is only called from the OnDateButtonClick method, which is also private and handles the Click event on a private Button.
Of course, as the control is open-source, you can take the source code of the control and make your own copy of it with one of these methods exposed. As far as I can tell, it's allowed under the Ms-PL.
I am writing a Windows Phone Application in C# and on my application page i have an image object that is currently filled with an image. However i have another image object on the same page as well as a button object. What i want to do it click the button, and once i have done so i want to copy the image from the filled image object and paste it into the blank object.
Is there a way of doing this, i read something about the use of a bitmap to do so but i'm not sure how to do it? Any examples or ideas of what code i could use would be greatly appreciated.
You can remember Image.Source and pass that to the other page and set it as a source for another image control.
It also depends on how you are filling the first Image control. If you are in the control of filling both controls, then you can just as easy use the same code to fill both controls.
I want to make a custom button in shape of a picture with C# for a Windows Store App?
Is there a way to do that from xaml? So far I've made a button and assigned a circle as a background image, but the problem is that even if I click outside the image the button works.
Also I do not believe that Image class has an event for click unfortunately.
I just recently implemented the WinRT XAML toolkit and it works wonder for me. It has an imagebutton control that might do what you want to do. http://winrtxamltoolkit.codeplex.com/
With the help of google: Walkthrough: Create a Button by Using XAML
You should have a look into Expression Blend. You can do all manualy in the XAML-Code but Blend is a huge help if you like to customize your project look and feel. Look at the MSDN-Examples.