WPF app "losing" icons - wpf

I have a large WPF app and recently we have had icons disappear. We have the images as external resources that get loaded into memory. We have a custom button template where we set an ImageSource for the icons to show up. I used procmon to see that the image files are loaded into memory. I used WPF Snoop to see that the buttons have the images set correctly. Only some of the icons will disappear and then if you start the app again they might all be there. Using snoop if I change the imagesource to one of the files that loaded and are displayed, then that one will also show up, but if i put a "bad" one into a button that loaded fine before, the icon is still gone. When they disappear it is the same ones that disappear. And occasionally the wrong icon all together will appear on one of the buttons.
The button template has an Imagesource setup for the image to load and display.
This is really puzzling because one time everything loads just fine and the next, some of the icons are not loading. They are all png files.
Any ideas where to look next? Thanks.

One reason I can think of is that you just have one instance of each image, so if you use it one place it will disappear in other places. If you have the resources defined in XAML you can set x:Shared="false": http://msdn.microsoft.com/en-us/library/aa970778.aspx
Otherwise you'd have to create additional instances manually from your code.

Related

Force visual layout of hidden tab content

I have some quite complex content behind several tabs. I'd like to force the layout to happen at application startup rather than lazily as the user clicks a tab for the first time. The delay is about a second or two per tab, and it's a bit embarrassing!
Edit: I think the problem is that only the selected tab's content control is in the visual tree. Calling ApplyTemplate of the HeaderedContentControl didn't make any difference.
Does this link help you?
wpf force to build visual tree
Basically it says to use ApplyTemplate on the ItemsControl...I guess that for the tabs you should do it for each TabItem.
There's also another technique used in this site:
http://xcalibur37.wordpress.com/2012/07/12/make-your-tabcontrol-preload-in-wpf-silverlight/
Here he creates a kind of preloader for each tab. It's for silverlight but I think it can be applied to WPF.
Hope it helps out :)

Overlay two Silverlight apps

I was wondering if it is possible to have two Silverlight apps overlway each other.
What I would like to do is have SilverlightApp1 take the whole browser window, then SilverlightApp2 show up as a popup in center of window as modal with transparent background. SilverlightApp2 would take up all window space too (to act as modal and block access to SilverlightApp1), but since the background is transparent it would act as modal and only have the main container element accessible.
Is this possible?
I was kind able to achieve this but not the transparency part of it...
I know there are easier solutions for this, but I am working inside an existing Silverlight application (which is SilverlightApp1 above) where I don't have the ability to modify much, but the HTML containing the app.
Thank you!
You could try to make a modal javascript window which overlays the div of SilverlightApp1 and place SilverlightApp2 on it. Maybe you should make SilverlightApp2 not to take up all window space and make the transparent/modal part with a div.
I think this could work.

viewing xaml loaded in the browser

Is there any way to view XAML tree loaded into a browser?
We are using one proprietary component, that loads xaml dynamically (Application.GetResourceStream), and there seems to be a problem with what it loads. How do I get a glimpse of xaml loaded?
Have you tried just wrapping the Stream returned by Application.GetResourceStream in a StreamReader to inspect the XAML?
Beyond that, Silverlight Spy is a great tool for inspecting the UI at runtime -- it lets you navigate the full visual tree and will even highlight what you've selected with a red rectangle inside the app.

Strange "frozen" content of WPF Window bug

A few of my users are experiencing a strange bug. I have a simple WPF window that contains a few textblocks and buttons. After a short time using my application successfully the users that experience the problem report that the window's content becomes empty and only the border of the window is visible.
After remoting onto their machines I have confirmed that it looks like the content of the window is frozen. When the window first opens it appears like its see through and displays whatever is behind it. If I move the window around the same frozen image of what was behind the window when it opened stays there. If I bring something in front of the Windows (such as a browser) the "frozen image" in the contents will change to a frozen image of whatever was in front of it. I have discovered that the buttons are still active and clickable in the window, so it's not completely frozen it just seems not to be drawing the content properly.
The issue only seems to affect a small percentage of my users and I cannot recreate this issue on any of my test machines. Any ideas about what is happening would be greatly appreciated.
If you have a user that's willing to experiment to find a solution, have them Disable Hardware Acceleration in WPF. If this fixes the issue, then it's most likely a graphics driver problem.

How to set a placeholder for a Image control (while it downloads)?

I have an app that show a list of images. The image source is set to a http URL, and the images are downloaded and display automatically.
However, while the app is taking time to download, the image control shows nothing. The user experience is not good this way.
How may I display a loading placeholder image, or a loading gauge, for each of the image control?
While an image is loading, it is drawn transparently. You can use this to your advantage to display an element underneath the image while it is loading. For example, you could have a stock image that is bundled with your XAP that represents a default avatar for example. Or you could display a XAML loading animation. Then when the image is finished loading, it will obscure the element behind it.
Mick's suggestion is a good one if you need to minimize your visual tree and if your scenario allows for a code solution. This suggestion is not perfect but it does make it easier to deal with the case where your placeholder image is unscaled/centered but the loaded image is scaled/stretched.
You could set the image source to your placeholder then when ImageOpened fires, change it to the remote url and let that run it's course.
In addition to the 2 other suggestions (from Josh & Mick) you could display a placeholder in the xaml and then, in code, download the actual desired image in the background using HttpWebRequest. Then when the image has fully downloaded save it to isolated storage and then update the source to the displayed image.
Yes this is more complex than the other solutions but would simplify the visual tree and avoid a blank image being displayed while the image is downloaded.
It would also give you offline caching of images too.
Interesting how many options there are for tackling this problem.
You might also like to consider Ben Gracewood's image caching implementation or what appears to be a development on that idea in his blog comments.
One-time Cached Images in Windows Phone 7 « Ben.geek.nz
Peter Nowaks Mobile Blog - “Intelligent” Image Caching for WP 7
Some background on the discussion leading up to this here if it's of interest.
Image control cache duration?

Resources