3

Afters attemps I could tell that the FocusVisualStyle is only activated by the keyboard (tab and arrows keys).

Try to make the FocusVisualStyle to be applied after the component is loaded, it is impossible to do, There is an easy way to get around this problem?

I found this:
- focus visual not showing when navigating focus programically
- How do WPF buttons decide to show FocusVisualStyle?
- http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/99856840-f8ef-4547-9150-c4c46ec2f3df

But none shows a definite solution (without overwriting the component), and I could not write, can someone help?

Community
  • 1
  • 1
J. Lennon
  • 3,311
  • 4
  • 33
  • 64

1 Answers1

0

I am not pretty sure I understand your issue, but I tried the example in one of the links and I was able to move focus to next component from code behind exactly as you would do using keyboard. Here is the code.

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:local="clr-namespace:WpfApplication1" Loaded="OnLoaded"
        >
    <StackPanel Margin="10">
        <TextBox Margin="10" x:Name="a" >A</TextBox>
        <TextBox Margin="10" x:Name="b" >B</TextBox>
        <Button Focusable="False" Click="OnClick">Move Focus</Button>
    </StackPanel>
</Window>

public partial class MainWindow : Window {
    public MainWindow() {
        InitializeComponent();
    }

    private void OnLoaded(object sender, RoutedEventArgs e) {
        a.Focus();
    }

    private void OnClick(object sender, RoutedEventArgs e) {
        var request = new TraversalRequest(FocusNavigationDirection.Next);
        var elementWithFocus = FocusManager.GetFocusedElement(FocusTest) as UIElement;
        if (elementWithFocus != null)
            elementWithFocus.MoveFocus(request);
    }
}
Jatin
  • 4,023
  • 10
  • 60
  • 107
  • 1
    try to make the FocusVisualStyle to be applied after the component is loaded, it is impossible to do and this is my problem – J. Lennon May 20 '13 at 11:35
  • I misunderstood your issue. Now I see your problem. Really sorry for that. – Jatin May 20 '13 at 12:05