Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is the equivalent of SetFocus()
Message
From
11/02/2009 13:41:17
 
 
To
11/02/2009 12:58:50
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01380470
Message ID:
01380998
Views:
45
Hi old friend... I'm back on my HolePatterns WPF project. Man this is fun. I was hoping you'd join in here.

Someone did give me this BeginInvoke solution from the MSDN WPF forum. Yours a little different becuase the delegate is defined inline, and only calls the Focus() method, whereas, I'm actually calling another method, which needs an object references passed in. It does few things, and then sets the focus.

(I'm gonna post the entire project soon, but in the mean time, here is a current screenshot.. http://twitpic.com/1f2ci/full)

Here is my code:
private delegate void focus(HolePattern NewActivePattern);

private void lvHolePatterns_SelectionChanged(object sender, SelectionChangedEventArgs e)
   {
     ListView lvSender = (ListView)sender;
     this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.SystemIdle,
                                           new focus(SetActivePattern), (HolePattern)lvSender.SelectedItem);
   }
and
       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" />
>>
>
>Not sure how far you got with this. But you probably need to do something like this:
>
>
>      Dispatcher.BeginInvoke(DispatcherPriority.Input,
>                            new ThreadStart(delegate()
>                            {
>                            txtPatternName.Focus();
>                            }));
>
>
>Focus does work, but has to be executed at the right time.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform