C# wpf weird repaint issue - wpf

I have experienced this intermittent issue with WPF.
Sometimes, when a Window is shown, it will have nothing except maybe a button visible. And after moving your mouse around and clicking on the window, the rest of it will become visible.
I don't know if this is an issue with WPF or maybe the UI library I am using.
Anyone has seen something like this?
Thank you.

Related

How to get IsActivated notification from the Windows Taskbar?

My specific issue is not being able to close a WPF Popup/Flyout when anything on the Taskbar is clicked. I have been able handle its closing from just about any other object, but the Taskbar remains a mystery.
I have looked into various ways to get Taskbar information (such as SHAppBarMessage), but it seems I can only know two specific states about the Taskbar, neither of which help me.
Does anyone have ideas?
The Window.Deactivated event is triggered by clicking the taskbar.

How do I create an expaning panel in Silverlight 4?

I'm a rank newbie at animations and so on in Siverlight, and have a need to create an expandable panel, which can be used as a help facility. The idea is that the screen would have a small button at the top-right, and when clicked, this would animate the width of a panel containing help info from zero to some width. Clicking the button again would shrink the help panel back to zero width.
This sounds like it ought to be really easy, and in WPF it is, but as Silverlight doesn't seem to support a lot of the functionality of WPF, I'm struggling badly here.
I looked at the expander control from the toolkit, but as far as I can see, this doesn't do what I want, as the control always takes up the same screen area. I want the expandable panel to disappear when it's not in use.
Anyone able to provide a simple example of how this could be done? Note that I'm using SL4, not SL5.
Thanks very much in advance.
If you've got access to Expression Blend, this can (almost) all be done in XAML.
This is a good place to get started
Found another SO question where someone posted XAML to do something almost identical...
Silverlight Project - Slide-in and out Panel - How?
Hope this helps someone else :)

Is there a SurfacePopup control in Surface 2?

We've been working on an application for the last few months that's aimed at Windows 7 tablet PCs. So we've used the Surface 2 SDK for most controls and it's all touch-happy.
I have noticed recently, though, that one of our custom controls isn't working as it should. This control provides popout menus, and these are achieved through the Popup control. On a developer's laptop, this works fine and the menus vanish when you click away from them. I've noticed, though, that on our test tablet they have a tendency to stay open.
I found that there was a SurfacePopup in the first Surface SDK, but I can't find one in the Surface 2 SDK. Did they get rid of it? Is there a 'best practice' approach?
If there's no simple solution, I may have to go old-school and add a window-sized hidden SurfaceButton below the menu when it appears, that hides itself and the menu when clicked or touched.
Beyond that I've noticed that sometimes the SurfaceScrollViewer within the popups won't work. I'm guessing this is because it's not picking up touch events properly. I tried adding this extension method to the window..
this.EnableSurfaceInput();
..but I get a NullReferenceException on System.Windows.Input.Mouse.get_LeftButton() which bizarrely suggests that it can only enable surface inputs for controls when there's a mouse plugged in.
Any ideas? They'll all be welcomed with open arms!
There's no SurfacePopup in the Surface SDK 2.0, however you can use a normal WPF popup. Then you need to make sure that it receives Touch Events by using the extension method you suggested above on the popup, not the window:
((HwndSource)HwndSource.FromVisual(popup)).EnableSurfaceInput();
Edit: As I just found out, this only works when the popup is initially open. To get it to work when the popup is opened later on, you don't need to use the popup, but the parent of it's child (see this question).
For the benefit of Daniel, and anyone else who needs a solution to this, I'll try to cast my mind back two years and explain how we got this working.
As far as I can remember, the answer was to use an adorner layer instead of a popup. Basically, every WPF control has an adorner layer, which sits above the control's UI stack. By default it contains nothing, but you can add whatever you like to it.
I got this all working by writing a custom control that allows you to place that control, with content, in the XAML and then show and hide it whenever you need to. When it's shown, it moves its contents into the adorner layer of the containing window, and when it's hidden it moves the contents back into the control itself, which is hidden from the user.
Afraid I can't go into any more detail than that, but as far as I can remember this was the ultimate solution; replacing popups (which never quite worked very well) with a custom control that uses the adorner layer.
Hope that helps!

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.

WebView containing Silverlight

In my cocoa application I have a WebView. If I set that WebView to display a web page that contains Silverlight, the mouse move event never fires in that Silverlight application (with the exception of if I hold down the mouse button while moving). Everything else seems to work fine (clicking, interacting with objects) except for mouse move. Anyone have any ideas what is causing this and how to fix it?
Found out what the problem was. When Silverlight is embedded in a WebView (from WebKit) appears to have different concerns regarding threading (Firefox on OS X does not exhibit this problem). The solution was making sure that anything that touched a UI Object was in a control.Dispatcher.BeginInvoke (specifically in my case I was changing the text on a TextBlock in response to a MouseMove and that was causing the whole MouseMove to error out).
Hope this helps someone.

Resources