WPF button enable/disable problem - wpf

I'm somewhat new to WPF and VB.Net (but not new to programming in general) and I was wondering if someone could help me with an issue that I'm having.
Here's the problem:
I am creating a simple form using WPF in VB.Net and I have a button that I want to disable or enable based on an update to a DataGrid that is located in the form. When I first show the form the button is enabled by default and everything is fine. When the DataGrid changes I can disable the button programmatically by doing btnTest.IsEnabled=False and the button grays out appropriately. However, when I subsequently call btnTest.IsEnabled=True the button becomes enabled all except for the text that is displayed on the button; that text remains grayed out. I can switch back and forth between enabled and disabled several times and the behavior described still manifests. I'm not sure if I'm missing something but this seems to be a really simple problem to me and I've wasted a few hours on it already.
Does anyone know what's going on? I've already googled everything I know.
Thanks
Tom

Just to update this: I actually found out that this was a bug in the BureauBlue theme that ships with .NET. If you have this problem tag me in a comment here and I can send you my modified BureauBlue.xaml file.

Related

Windows 8 like modal dialog using WPF

I am working on a WPF-MVVM (.Net 4.0) application that has a Metro look (it just has a look, it is not a metro application.)
I need to show a windows 8 like message box that blocks the operations for the user before he rids that message box by clicking yes/no/cancel (or any button.).
I came across this otherwise great article and momentarily thought that I have found the solution. But this has its own drawback.It just stops the user from interacting with the controls behind by mouse clicks. The user can however use the tab key to get back to the buttons behind and click them (pressing enter).
A number of things are coming to my mind:
should I go for custom adorners and play with hitTestable property?
Or should I place a control and play with its visible property.
Before going for any approach I thought of putting forward my question to the wonderful community here if someone has done a similar thing in past and provide me some pointer/reference/approach.
Can someone suggest what is the way to achieve this? Please note I will be happy to use prism or any other open source if that solves the purpose but the window will have to be custom made.
Please excuse me if you find this too stupid a question. Please pardon my ignorance. Thanks for reading this.
I recently came across a similar problem, I resolved it using a DialogPresenter as explained there:
http://www.codeproject.com/Articles/36516/WPF-Modal-Dialog
I had to do a few tweaks there and there but overall it's working fine and I now have a nice way to display dialog boxes!
There is a better way of doing it
var dialog = new MessageDialog("Select Social network is already authorised!");
dialog.ShowAsync();

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!

DevExpress PivotGrid (Silverlight) : Popup Menus don't popup

We are using DevExpress Silverlight PivotGrid (11.2.7). The problem is that none of the popups work as one would expect.
Here is the xaml code (note that all of these properties are True by default and don't need to be set)
<dxpg:PivotGridControl
x:Name="pivotGrid"
... data bindings ...
IsFieldValuePopupMenuEnabled="True"
IsHeaderMenuEnabled="True"
IsHeaderAreaMenuEnabled="True"
/>
Once the host control for the grid is shown and the data is loaded right-clicking on any of the relevant areas doesn't bring either of the popups (there are 3).
Strangely (or not so strangely) in the sample SL project provided by devex everything works as it should.
The one (significant) difference between the sample app and our project is that we are using MEF and relevant .xaps are loaded dynamically based on which user logged in and some other stuff.
We have tried a lot stuff to figure out what is wrong but haven't managed to find anything even remotely relevant. Here is what we have tried :
Adding the pivotgrid to the host tabpage in codebehind after imports have been satisfied;
Setting / resetting properties mentioned above after imports from codebehind;
Adding the control to the startup page of the project before the MEF madness kicks in;
We also tried to popup the menus manually by inheriting from the pivotgrid control, but that has not yielded much;
Enabled RedrawRegions to make sure the popup is not popping 'under'. It's not;
Any pointers or ideas would be greatly appreciated.
Regards,
Alex
It appears that this was some bug in the version we were using at the time.
After updating to 12.1 everything works like it should without any tinkering from our side.
Looks like devex guys have bugs too...who knew right :)

Question about changing dialog box layout

Hey, I just got started designing dialog boxes and windows forms, and I had a basic question.
When you use something like a windows installer, it has a next button, and when you click it the dialog completely changes layout in moving on to the next step. My question is, is this done by loading a completely new dialog box and getting rid of the previous one. Or is there some way of making a dialog with multiple pages/states (not sure what to call them).
Thanks in advance for any help.
Wizards are usually made using the property sheet control from the Common Controls library. They do not create a new dialog, but use something similar to tab pages instead.

Windows App Focus: Why does it require a click?

When I have 2 apps open and one has the focus but I want to execute a command in the other app, it requires a click to regain focus and another to execute the command. Is there some good reason why I couldn't take focus on MouseOver? I'm working with a WPF app if that is pertinent. TIA
EDIT: Oddly enough the MouseOvers work without focus.
I would not recommend doing this. This is not a standard way of working in Windows, so you will confuse your users. People are used to clicking into an application (or tabbing) to provide focus.
However, this is a configurable setting via the Accessability Tools in Windows. It can be enabled by choosing "Activate a window by hovering over it with the mouse" globally. Let your users specify this behavior if they want it.
The setting is configurable at a system-wide level. You should never ever override the user's current setting regarding this.
MS Windows Vista -- focus follows mouse (There's also a link on how to do it on XP.)
Edit: Normally, you can click a button on a form and both bring focus to the window and click it at the same time. The origins of the current setting "eating" the initial mouse click that brings focus to a window started as a fix to a bug in the Ribbon UI. The discussion is somewhere in this video: The Story of the Ribbon. Sorry I can't narrow it down more than that, but at least the video is a great insight and work watching - maybe you can send a message to Jensen Harris if you need a faster answer.
Edit 2: I just added a button to a WPF window, and I'm able to click it as long as I can see it - whether or not the window has focus.
You can take focus on MouseOver manually

Resources