Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
About my WPF app to draw a Bolt Hole Pattern.
Message
De
09/08/2008 15:25:34
 
 
À
06/08/2008 20:11:13
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01334102
Message ID:
01337809
Vues:
15
OK, got your cdsSpinner up and running in my HolePattern App... But with one problem I need help with. I think I've got a read on what's happening:

Back when I had my UI buttons as dedicated "+" and '-" buttons to do the work that your arrow buttons do, I had the click event of each button firing a method in the code-behind that would increase or decrease the HoleCount property on the HolePattern instance, and because of the PropertyChanged mechanism, it updated the Textbox, and I also had a PropertyChanged event handler that updated the Canvas view. Everything worked great.

However, when using your cdsSpinnder control, each time I click (let's say) the Up arrow, it is updating the Text property and the displayed value in the Textbox, but it does not seem to trigger the Property changed event handler, UNTIL I press Tab, which passes focus to the Down arrow but does trigger the event, or when I click into some other control in the UI, that also triggers the event. I guess it it not updating the bound property UNTIL the control loses focus?

So I guess the major deisgn difference is that with my buttons I was driving a property on a specifice class instance, and you are driving the value of the textbox. No big deal, just gotta think about how to do a little more wiring.


I had 2 ideas on how to attack this:

Idea 1: The XAML declares the binding of the Textbox, so I wonder if there is a way to read that binding, and then in the _SpinUp_Click() and _SpinDown_Click(), do what would equate to (pseudoc code) "BoundProperty+=1" which would evaluate in my case to "HolePattern1.HoleCount+=1". It seems like this would solve it in a generic way, at least when the Textbox uses binding. I suppose you could have an "If" statement, and use your current method if no binding is defined, and use this approach if binding is present. If this is a good architectural choice, then I still do not know how to implement it in real code.

Current XAML:
<local:cdsSpinner x:Name="txtHoleCount1" Text="{Binding Path=HolePattern1.HoleCount, ElementName=winBoltCircle}"
     PreviewGotKeyboardFocus="TextBox_PreviewGotKeyboardFocus" Height="25" Width="75" Style="{StaticResource cdsSpinnerStyle}"/>
Idea 2: Some other way to force a broardcast that the value has changed. Right now, that does happen until focus changes to some other control. I threw a MoveFocus in the _SpinUp_Click() method to move focus and then come back. It does have the desired effect, but a shameful approach.
        void _SpinDown_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            int val;
            int.TryParse(Text, out val);
            val -= 1;
            Text = val.ToString();
            this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
        }
Idea 3: I guess we could create a TextChanged event handler in code-behind, but I really hope this can be avoided.


If I will just stop typing, you probably already knew a good solution as soon as you began reading my message.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform