Images can not be set from ViewModel's constructor #15164
Unanswered
Seekuhnetz
asked this question in
Q&A
Replies: 2 comments 3 replies
-
Thanks for the report. Just to be sure, the behavior you're seeing is in the |
Beta Was this translation helpful? Give feedback.
3 replies
-
Hello, sorry for the necroposting
Inside those streams are the bytes from the decoded image, but the main part is that probably you need to do it inside |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Current behavior
It is not possible to set an ImageSource in the constructor of a ViewModel and bind it to the View.
For example:
In the MainView:
<Image Source="{Binding ImageSourceFromConstructor}" Width="100" />
In the MainViewModel:
A ComException will be thrown.
Expected behavior
It should be possible to set the ImageSource from the ViewModel at creation?
How to reproduce it (as minimally and precisely as possible)
ZIP:
ImageException.zip
Workaround
Of course you could not use binding:
<Image Source="ms-appx:///ImageException/Assets/Images/dotnet_bot.png" Width="100" />
Or you could use this workaround with events in the code behind:
In the ViewModel you will need to set the ImageSource from a RelayCommandMethod:
Works on UWP/WinUI
None
Environment
No response
NuGet package version(s)
No response
Affected platforms
Windows
IDE
Visual Studio 2022
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
Or is there maybe a better and working way to set the images from the ViewModel?
Beta Was this translation helpful? Give feedback.
All reactions