I have WPF form and say I have a textbox, button X, button Y and couple of hyperlinks. Button x and textbox are initially visible and button Y, hyperlinks are hidden(will be visible when user clicks button X).
When I press tab, focus goes over hidden hyperlink, it won't make them visible though, but still shows a focus on a kind of place holder, which looks bad.
So, basically, I want to disable tabindexing for hidden elements and enable for visible elements
Below is part of my XAML file...
<pre><Window x:Class="WPF_TabIndexDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPF_TabIndexDemo"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Border BorderThickness="0" BorderBrush="#FF999999" Margin="1,1,1,1">
<Border.Effect>
<DropShadowEffect Color="#cccccc" Opacity="0.83" Direction="60" BlurRadius="50"/>
</Border.Effect>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="0*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label x:Name="Label" Content="JioCloud" Grid.RowSpan="2" VerticalAlignment="Top" VerticalContentAlignment="Center" Margin="-1,-1,-1,0" Height="26" Padding="30,0,0,0" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" FontSize="13" FontWeight="Regular">
<Label.Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#f4f4f4" Offset="0"/>
<GradientStop Color="#d4d1d4" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</Label.Style>
</Label>
<Image x:Name="Image" HorizontalAlignment="Left" Height="16" Margin="8,4,0,0" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Top" Width="16" RenderTransformOrigin="0.5,-3.286" />
<Button x:Name="BtnClose" Command="{Binding CloseWindowCommand}" Width="24" Height="24" Margin="606,-1,-2,416"
Grid.Row="0" Grid.RowSpan="2">
<Image Width="12" Height="12" Margin="4,6,4,2" />
</Button>
<Button x:Name="BtnMinimize" Command="{Binding MinimizeWindowCommand}" Height="24" Width="24" Margin="584,2,20,413"
Grid.Row="0" Grid.RowSpan="2">
<Image Width="12" Height="12" Margin="6,9,6,3" />
</Button>
<Grid Margin="141,122,136,50" Grid.Row="0" Grid.RowSpan="2" Background="White" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox HorizontalAlignment="Left" x:Name="TbEmailAddress" VerticalContentAlignment="Center" VerticalAlignment="Center" Width="350" BorderThickness="0,0,0,2" Margin="0,79,0,162" TextOptions.TextHintingMode="Animated" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Bold" FontSize="15" Grid.ColumnSpan="2" Foreground="Black" Background="White" Height="25" BorderBrush="#FF9B9B9B" >
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="#c41215"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=LbEmailError, Path=Text}" Value="">
<Setter Property="BorderBrush" Value="#7d7d7d" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=LbEmailError, Path=Text}" Value="{x:Null}">
<Setter Property="BorderBrush" Value="#7d7d7d" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<TextBlock x:Name="TbForgotPassword" Background="White" Foreground="#FF9B9B9B" HorizontalAlignment="Left" Height="21" Margin="254,81,-18,164" VerticalAlignment="Center" Width="115" Grid.ColumnSpan="2"
Grid.Column="0" Visibility="Hidden">
<Hyperlink Foreground="#FF9B9B9B" Background="White" FontSize="13" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" NavigateUri="https://www.jio.com/Jio/portal/forgotPassword" TextDecorations="None">
<Run Text="Forgot Password" />
</Hyperlink>
</TextBlock>
<TextBlock x:Name="TbResendOtp" Background="White" Foreground="#FF9B9B9B" HorizontalAlignment="Left" Height="21" Margin="280,80,-17,165" VerticalAlignment="Center" Width="88" Grid.ColumnSpan="2"
Grid.Column="0" Visibility="Hidden" >
<Hyperlink Foreground="#FF9B9B9B" Background="White" FontSize="13" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" NavigateUri="https://www.jio.com/Jio/portal/forgotPassword" TextDecorations="None">
<Run Text="Resend OTP" />
<LineBreak></LineBreak>
</Hyperlink>
</TextBlock>
<TextBlock x:Name="TbGoBack" Foreground="#FF9B9B9B" HorizontalAlignment="Center" Height="28" Margin="132,199,154,39" VerticalAlignment="Center" Width="65" Grid.ColumnSpan="2"
Grid.Column="0" Visibility="Hidden" RenderTransformOrigin="0.658,0.571" KeyboardNavigation.TabNavigation="None">
<Hyperlink Foreground="#FF9B9B9B" FontSize="14" FontWeight="ExtraBold" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Bold" NavigateUri="https://www.jio.com/Jio/portal/forgotPassword" >
<Run Text="Go Back" />
</Hyperlink>
</TextBlock>
</Grid>
<Button x:Name="BtnLogin" Cursor="Hand" BorderThickness="50" HorizontalAlignment="Center" Content="LOGIN" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" VerticalAlignment="Center" Width="128" Height="35" Margin="240,264,260,139"
Grid.Row="0" Grid.RowSpan="2" IsDefault="true" FontSize="15" Foreground="#FFF9F3F3" Visibility="Hidden">
</Button>
<Button x:Name="BtnContinue" Cursor="Hand" BorderThickness="50" HorizontalAlignment="Center" Content="Continue" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" VerticalAlignment="Center" Width="128" Height="35" Margin="240,272,260,131"
Grid.Row="0" Grid.RowSpan="2" IsDefault="true" FontSize="15" Foreground="#FFF9F3F3" Click="BtnContinue_Click">
</Button>
<TextBlock Grid.Row="0" Height="25" Grid.RowSpan="2" x:Name="PolicyLabel" Margin="147,414,115,-1" Foreground="Gray">
<TextBlock Width="305" Height="17" Padding="2" FontSize="9" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.544,0.294">By proceeding with login, you agree with
<Hyperlink x:Name="TermsOfServiceHyperlink" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" FontSize="9" NavigateUri="https://static.jiodrive.com/tos.html" >Terms of service
<Hyperlink.Style>
<Style>
<Setter Property="Hyperlink.Foreground" Value="DarkOrange"></Setter>
<Style.Triggers>
<Trigger Property="Hyperlink.IsMouseOver" Value="True">
<Setter Property="Hyperlink.Foreground" Value="#F37F20"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Hyperlink.Style></Hyperlink>
<TextBlock Padding="2" FontSize="9" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" Text="&" VerticalAlignment="Top"/>
<Hyperlink x:Name="PrivacyPolicyHyperlink" FontFamily="/JioCloud;component/Views/Fonts/#JioType-Light" FontSize="9" NavigateUri="https://static.jiodrive.com/privacypolicy.html">Privacy policy
<Hyperlink.Style>
<Style>
<Setter Property="Hyperlink.Foreground" Value="DarkOrange"></Setter>
<Style.Triggers>
<Trigger Property="Hyperlink.IsMouseOver" Value="True">
<Setter Property="Hyperlink.Foreground" Value="#F37F20"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Hyperlink.Style></Hyperlink>
</TextBlock>
</TextBlock>
</Grid>
</Border>
</Window>
What I have tried:
1. I tried to set
Focusable="False"
but it doesn't work.
2. Set
KeyboardNavigation.TabNavigation="None"
It works...
BUT, it's a static change. I.e. When I make those hyperlink visible, there is no way to tabindex on them. This is because I can't set
KeyboardNavigation.TabNavigation=none dynamically.
how can I set
KeyboardNavigation.TabNavigation="None" for hidden elements only.
3. Tried to use TabStop, but it's available for Forms and not for Windows