Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is the equivalent of SetFocus()
Message
From
11/02/2009 12:20:47
 
 
To
11/02/2009 11:57:35
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01380470
Message ID:
01380952
Views:
49
Hi,

Snip from the solution: "Actually after calling the "SetActivePattern" the control return to the Listview changed event and it retun to ListView. So again the Focus moved to ListView."

I don't see this. Here's a simple version:
<Window x:Class="WpfApplication1.Junk"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Junk" Height="300" Width="300">
    <StackPanel>
        <Button Height="23" HorizontalAlignment="Left" Margin="50,30,0,0" Name="button1" VerticalAlignment="Top" Width="75">Button</Button>
        <TextBox Height="23" Margin="40,66,88,0" Name="txtPatternName" Text="{Binding Path=PatternName, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" VerticalAlignment="Top" />
        <StackPanel>
            <ListBox Height="65" Margin="59,0,120,45" Name="listBox1" VerticalAlignment="Bottom" SelectionChanged="listBox1_SelectionChanged" >
                <ListBoxItem>One</ListBoxItem>
                <ListBoxItem>Two</ListBoxItem>
                <ListBoxItem>Three</ListBoxItem>
            </ListBox>
        </StackPanel>
    </StackPanel>
</Window>
with
       private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            txtPatternName.Focus();
        }
This seems to work fine - why did your code behave differently?
Regards,
Viv




>Well. problem solved...Got a working answer from the WPF forum on http://social.msdn.microsoft.com/Forums/en-US/wpf/threads/
>
>Here is the reply from that smart person that works perfectly. There may be other solutions, but I can say that this one did indeed work:
>
>
>Hi,
>
>Actually after calling the "SetActivePattern" the control return to the Listview changed event and it retun to ListView. So again the Focus moved to ListView. To overcome u start the SetActivePattern function in a Dispatcher.Invoke or BeginInvoke with System Idle priority u get the focus in text pattern. See the sample below
>
>define a delegate
>private delegate void focus(HolePattern NewActivePattern);
>
>paste the below code inside the lvHolePatterns_SelectionChanged
>
>this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.SystemIdle, new focus(SetActivePattern),
>(HolePattern)lvSender.SelectedItem);
>
>Hope this helps
>Regards
>Anandakumar.R
>
>
>
>
>
>
>>Hi Matt,
>>
>>Have you checked the KeyboardNavigation.TabNavigation property? This property controls how navigation is handled in WPF containers.
>>
>>Focus can fail for any of the following reasons:-
>>
>>1] Element Enabled = false
>>2] Element IsVisible = false
>>3] Element Focusable = false
>>
>>Or
>>
>>4] Element is in a control and not the main xaml (not been loaded)
>>5] LostKeyboardFocus and PreviewLostKeyboardFocus are preventing it
>>
>>Where you are trying to set the Focus in your code put a new line in that makes a call to the textbox PredictFocus method and set a breakpoint. PredictFocus will not shift the focus but it will tell you what should be focused next and help resolve containers that are not releasing the focus.
>>
>>HTH
>>Neil
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform