Why does so much stuff in WPF not work ? [modified]
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
I would not have been able to help with your problem, if you hadn't already solved it, as I am struggling with WPF myself. WPF appears to me to be so much more difficult than it needs to be in almost all aspects.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
I would not have been able to help with your problem, if you hadn't already solved it, as I am struggling with WPF myself. WPF appears to me to be so much more difficult than it needs to be in almost all aspects.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
I always tell my boss, WPF makes almost anything possible. It does that by making every little thing very flexible, but very complicated as a result. I agree tho, it shouldn't be as bad as what it is.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
It is a constant source of frowning for me. After decades of activity in UI software development that the tools to design, create and maintain them are still so so so hard to use, fragile and seemingly ill-fitting to the problem domain. One would think after so much research, use and development it would be a solved problem by now. Sigh. One of the funniest and representative moments for me was when I started doing C# work. I had been working in the Java desktop space for a few years and was very familiar with it, particularly layout managers. Come Java 1.5 and 1.6 they had released a set of new layout managers and modified the core part of swing to support them (aligning to text baselines, so obvious in hindsight). They were fantastic. They solved layout issues so easily and superseded all the grid layouts and previous hacks people used to work around things. I love you GroupLayout. Then I moved to C#, and imagine the surprise when the layout mechanisms were the same as Java's, but from 4 years prior. Grid layout, flow layout and docking along edges. Sigh. Insert sad smiley here. On a related topic, I miss Java 1.5 synchronization mechanisms. They made things so much easier. java.util.concurrent - I miss you.
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
As you know, I don't do much WPF these days except for demo apps and pet projects - but I find it far more appealing than WinForms. I do run into dead-ends once in a while and it takes me longer to figure out compared to WinForms, but it's still fun (specially since I don't have a deadline or a boss who's waiting for an update for these home projects) :-)
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
-
As you know, I don't do much WPF these days except for demo apps and pet projects - but I find it far more appealing than WinForms. I do run into dead-ends once in a while and it takes me longer to figure out compared to WinForms, but it's still fun (specially since I don't have a deadline or a boss who's waiting for an update for these home projects) :-)
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
Yeah, I agree, the end result is so plain cool that I'd never use winforms anymore. The issue is, why are there so many bugs that surely someone would have noticed, if any testing was done. Remember the mouse focus bug you found ? That sort of stuff just comes up far too often.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
There are many such bugs in Silverlight too. Hopefully, someone is listening and will fix them soon.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.
-
Yeah, I agree, the end result is so plain cool that I'd never use winforms anymore. The issue is, why are there so many bugs that surely someone would have noticed, if any testing was done. Remember the mouse focus bug you found ? That sort of stuff just comes up far too often.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Joe Manager assigned WPF testing to the VS2010 team, which got priority order from Sarah Managerette "If it doesn't crash on my desk, you ship it".
Agh! Reality! My Archnemesis![^]
| FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy -
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
-
There are many such bugs in Silverlight too. Hopefully, someone is listening and will fix them soon.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
Yes, I agree it's annoying that WPF TextBoxes don't behave by default the way Windows edit controls have behaved since Noah was a lad (by selecting all the text when they get focus). The fact is, however, that it's very easy to achieve this for every TextBox in your application with very little code. This is obviously not a programming question so I won't answer it here. If it was a programming question in the appropriate forum I would say: ... ... just add this somewhere in your app initialisation:
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent,
new RoutedEventHandler((sender, args) =>
{
(sender as TextBox).SelectAll();
}));easy-peasy!
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
-
It's not that bright a side. Swing + JavaFX = lots of fun and actually pretty cool. And the added bonus is JavaFX is way easier to read than XAML.
-
There are many such bugs in Silverlight too. Hopefully, someone is listening and will fix them soon.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.
Abhinav S wrote:
There are many such bugs in Silverlight too.
I'm not surprised--Silverlight seems like WPF-light, wouldn't there be some sharing of the base code? On the other hand, I'm not surprised for other reasons as well. Marc
-
My 5, and your link is now in my favorites.
Software Zen:
delete this;
-
Yes, I agree it's annoying that WPF TextBoxes don't behave by default the way Windows edit controls have behaved since Noah was a lad (by selecting all the text when they get focus). The fact is, however, that it's very easy to achieve this for every TextBox in your application with very little code. This is obviously not a programming question so I won't answer it here. If it was a programming question in the appropriate forum I would say: ... ... just add this somewhere in your app initialisation:
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent,
new RoutedEventHandler((sender, args) =>
{
(sender as TextBox).SelectAll();
}));easy-peasy!
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
You know, I'm not sure it's true that the Windows edit control behaves this way. I recall working with standard USER controls in Win32, and when you select a control, the text wouldn't get highlighted automatically. I had to put the highlighting coding in myself on focus.
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
I feel your pain. I'm trying to convert a large winforms app (with visual inheritance used all over) to WPF and I'm nearly bald now from pulling all my hair out. If anyone has any way to do visual inheritance in WPF it would make my job so much easier. As it is I now have to make my code base about 100 times bigger without it. And if anyone asks my boss asked me to convert it. I consider it a total waste of time, but he pays the bills so I'm doing it.
-
someone desperately need a captcha tool on their blog...
-
All I want is, when I click on a text box, the text is all selected so the user just has to type to wipe it. All the xxx events do not work, only the Previewxxx events get called. Still not sure why. I tried PreviewGotFocus. The text gets focused, then when I lift the mouse, the focus is lost. I don't handle any other events on these controls. So I handle PreviewMouseUp. This seems to work, but there appears to be a bug in WPF. If I call SelectAll() on the control, it toggles, if I click on a control, then click on another, then click back, it DESELECTS all. So, I tried adding code to clear the selection first, makes no difference. Then I added code to manually set the selection. This works, BUT, now when I have selected the text, the app will take no more mouse input until I focus on another window, then focus back. I added code to set the focus to the control, this makes no difference. This mess is what I have now, and it still does not work. private void ProcessMouseUp(object sender, MouseButtonEventArgs e) { TextBox tb = sender as TextBox; if (tb != null) { tb.Select(0, 0); tb.SelectAll(); tb.SelectedText = tb.Text; tb.Focus(); } } I googled it and found a class that does what I want. Yes, you have to write your own control to do this. I wasn't asking for help anyhow, my question remains, why is this so complicated ? Why is it so buggy ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Monday, September 20, 2010 7:51 PM
A common practice is to show a modal dialog, then set the
DialogResult
value and close it, which works, except if you show a second modal dialog from the first, the minute you setDialogResult
on the first you get an error saying that you can only setDialogResult
if you usedShowDialog()
:(( VERY frustrating... I have a workaround, but it isn't really pretty...____________________________________________________________ Be brave little warrior, be VERY brave
-
I would not have been able to help with your problem, if you hadn't already solved it, as I am struggling with WPF myself. WPF appears to me to be so much more difficult than it needs to be in almost all aspects.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
"WPF appears to me to be so much more difficult than it needs to be in almost all aspects." This appears to be a characteristic of Microsoft development software in general. Unless you've done it many times before and know the quirks, doing anything new with a Microsoft development environment often runs into landmines. Things simply don't work, and tasks that should take minutes take hours or days. It's as if they see all other developers as potential competition, and put roadblocks in the way to slow them down.