Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What is the equivalent of SetFocus()
Message
De
10/02/2009 11:16:45
 
 
À
10/02/2009 10:54:17
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01380470
Message ID:
01380558
Vues:
49
>Sure. But I don't promise to be able to try it right away - I'm battling with Transforms at the moment !

OK, then. I'll wait till it's more complete. It has come a long way, but I'm still tweeking on it.

Did you look at the screenshot?



>But did Keyboard.Focus() work ?

Did not. Same exact result.

If I call the SetActivePattern() method programmatically, focus does change to the textbox.

But, when if I click on the listview, and it's lvHolePatterns_SelectionChanged() method fires, which calls SetActivePattern(), it does not change focus. The listview hold on somehow.




>Regards,
>Viv
>
>>You want a copy of my current code?
>>
>>
>>>Hi,
>>>
>>>Hard to say why txtPatternName.Focus() didn't work without being able to try it...
>>>Have you tried "Keyboard.Focus(txtPatternName)" instead?
>>>
>>>I'm also finally getting back to WPF, hopefully pretty much full time barring interruptions :-}
>>>Maybe this category will pick up a bit again :-}
>>>
>>>>Remember that Hole Patterns program I was working on back in the fall? We'll, I'm back on that...
>>>>
>>>>Before, I had the WPF UI that was hard-coded for two HolePatterns that could be defined.
>>>>
>>>>Well, now I have expanded it so you can add as many HolePatterns as you want, so, I have a listview which shows the HolePatterns collection, and when you click on a HolePattern in the list, it sets the DataContext of the next UI stackpanel to be focused on the SelectedItem and all the controls in that stackpanel now update.
>>>>
>>>>It all works well, I just want the focus to move to the PatternName textbox when the user clicks on a HolePattern in the listview. But, when I click on a HolePattern in the ListView, it updates the next stackpanel properly, but focus does not move to the textbox.
>>>>
>>>>Here is a screenshot: http://twitpic.com/1f2ci/full
>>>>
>>>>I'm using the listview.SelectionChanged event to update everything, so that is where my .focus() command is triggered:
>>>>
>>>>
>>>>                <ListView x:Name="lvHolePatterns" HorizontalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Visible"
>>>>                   Background="#FF75829E" SelectionChanged="lvHolePatterns_SelectionChanged">
>>>>
>>>>
>>>>
>>>>        private void lvHolePatterns_SelectionChanged(object sender, SelectionChangedEventArgs e)
>>>>        {
>>>>            ListView lvSender = (ListView)sender;
>>>>            SetActivePattern((HolePattern)lvSender.SelectedItem);
>>>>        }
>>>>
>>>>
>>>>
>>>>       private void SetActivePattern(HolePattern NewActivePattern)
>>>>       {
>>>>               ActivePattern = NewActivePattern;
>>>>               HolePatternStackPanel.DataContext = ActivePattern;
>>>>               CoordinateGrid1.ItemsSource = NewActivePattern != null ? ActivePattern.HoleList : null;
>>>>               RedrawScreen();
>>>>               txtPatternName.Focus();
>>>>       }
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>>What C# code would I use to set the focus to the named WPF TextBox below:
>>>>>>
>>>>>>I've tried txtPattern.Focus(), but it does nothing.
>>>>>>
>>>>>>
>>>>>>
>>>>>><TextBox Name="txtPatternName" Text="{Binding Path=PatternName, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Width="150" />
>>>>>>
>>>>>
>>>>>Hi,
>>>>>
>>>>>Neil gave you a good link. But in the simple case the 'txtPattern.Focus()' should work (at least it does for me). Any sample repro code?
>>>>>Regards,
>>>>>Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform