Search code examples
tabswpf-controlstabnavigatorkeyboard-navigation

WPF: Tab through textboxes in user controls in a Treeview


I'm trying to implement the Tab function in my application, but it seems like nothing i try works, so i guess i just don't understand how it is intended to be used.

I have a User Control (lets call it MyControl) which contains a Text Box (as well as other stuff). The MyControl is used with a Tree View. It looks like this for the user (+ signs reveals the entire user control, aswell as child MyControl if there is any, Red Arrow shows expected Tab behavior): Yolo

In MyControl i've set IsTabStop to false for all control except TextBox, well i've pretty much set my entire application to have IsTabStop = false. I've tried setting KeyboardNavigation.TabNavigation to both "Cycle" and "Continue" on both MyControl and the TreeView, as well as the page and window that contains the TreeView. And i've tried in different combinations (cycle on treeview, continue on mycontrol and vice versa, etc).

I also tried setting TabIndex to the have the same order that the MyControl objects are created. (So the top one gets 1, second one gets 2, etc).

But nothing that i have tried (in all different combinations) has ever even made tab go into the TextBox that i want it to go into. So my problem is not only that the order is wrong, It just selects the "treeview", making a dotted square around it. If i change some settings the focus just goes haywire to random elements, but never the textbox

So, what am i doing wrong? How is Tab supposed to be implemented?

Don't know what code to show, but: MyControl:

<UserControl x:Class="SinusManager.View.ParamNodeV"
         //blaablaa
         x:Name="pn"
         KeyboardNavigation.TabNavigation="Continue"
         IsTabStop="True">
         //blaablaa
         <StackPanel Background="{StaticResource Milky} KeyboardNavigation.TabNavigation="Continue">
   <Grid>
   //blaablaa
        <TextBox x:Name="ValueBox" VerticalContentAlignment="Center" PreviewTextInput="NumberValidationTextBox" FontFamily="{StaticResource MonoFont}" Text="{Binding Path=ValueText, ElementName=pn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Margin="130,0,0,0" VerticalAlignment="Top" Height="26" Width="92"
                  IsTabStop="True" KeyboardNavigation.TabNavigation="Continue" IsReadOnly="{Binding Path=ReadOnly, ElementName=pn}">
    //blaablaa

TreeView UserControl

<UserControl x:Class="SinusManager.View.ParamFrameV"
  //blaablaa
  x:Name="pf"
  KeyboardNavigation.TabNavigation="Cycle">
  <Grid>
    <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" Margin="0,0,0,0">
        <i:Interaction.Behaviors>
            <v:BubbleScrollEvent/>
        </i:Interaction.Behaviors>
          //blaablaa
         <TreeView Margin="0,16,0,0" KeyboardNavigation.TabNavigation="Cycle" ItemsSource="{Binding Nodes}" Background="{StaticResource Milky}" BorderThickness="0" ItemContainerStyle="{StaticResource TreeViewItemExpandedStyle}" HorizontalAlignment="Left" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                <TreeView.Resources>
                    <HierarchicalDataTemplate DataType="{x:Type vm:ParamTextNodeVM}" ItemsSource="{Binding Path=Nodes}">
                        <v:ParamNodeV Node="{Binding Path=NodeM}" Status="{Binding Status, Mode=TwoWay}" IsTabStop="True" NameText="{Binding Path=Name}" UnitText="{Binding Path=Unit}" ValueText="{Binding Path=Value, Mode=TwoWay}" RangeText="{Binding Path=Range}" ValueTypeText="{Binding Path=ValueType}" DescriptionText="{Binding Path=Description}" ReadOnly="{Binding Path=ReadOnly}" GetParameter="{Binding GetParameterCmd}" SendParameter="{Binding SendParameterCmd}"/>
                    </HierarchicalDataTemplate>
                //blaablaa

Code above does not have the binding for TabOrder that i tried, i removed it since it did not work. But basically i had a integer that counted up for every new MyControl created and added to the TreeView and used that integer to set TabIndex on the control. No, difference in behavior with or without the TabOrder (and yes, the binding worked).

EDIT: Still no answears, i guess i will dump all code here, maybe someone will spot something, I really want to fix this.

MainWindow:

<Window x:Class="SinusManager.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:SinusManager"
    xmlns:v="clr-namespace:SinusManager.View"
    xmlns:vm="clr-namespace:SinusManager.ViewModel"
    mc:Ignorable="d"
    Loaded="Window_Loaded"
    Closing="Window_Closing"
    ContentRendered="Window_Shown"
    Title="NFO Sinus Manager" Height="450" Width="800" Background="{StaticResource Milky}"
    Style="{StaticResource WinAll}" ForceCursor="True" MinHeight="375" MinWidth="500"
    KeyboardNavigation.TabNavigation="Cycle">
<Window.DataContext>
    <vm:MainViewModel/>
</Window.DataContext>
<Grid>
    <DockPanel>
        <Frame Source="View/Pages/StartPage.xaml" x:Name="MainFrame" NavigationUIVisibility="Hidden"/>
    </DockPanel>
</Grid>

MainPage:

<Page x:Class="SinusManager.View.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:local="clr-namespace:SinusManager"
  xmlns:v="clr-namespace:SinusManager.View"
  xmlns:vm="clr-namespace:SinusManager.ViewModel"
  mc:Ignorable="d" 
  d:DesignHeight="450" d:DesignWidth="800"
  Title="MainPage"
  KeepAlive="True"
  KeyboardNavigation.TabNavigation="Cycle">

<Grid Background="{StaticResource White}" KeyboardNavigation.TabNavigation="Cycle">

    <v:IconButton x:Name="BackHomeBTN" Image="{StaticResource BackHomeBTN}" Margin="0" VerticalAlignment="Top" HorizontalAlignment="Left" IconHeight="24" IconWidth="36" ColorPalette="{StaticResource WhiteSolid}" ColorPaletteFore="{StaticResource BlackToBluePalette}" Click="BackHomeBTN_Click" ToolTip="{StaticResource ToolTipHome}" Focusable="False" IsTabStop="False">
    </v:IconButton>

    <Label Margin="55,10,0,0" Content="{Binding InverterInfoPanel.Name}" FontFamily="{StaticResource MainFont}" FontSize="16" FontWeight="Bold"/>

    <Grid Margin="0,0,0,0" KeyboardNavigation.TabNavigation="Cycle">

        <!-- TOOL BAR-->
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Height="50" Background="{StaticResource White}" Focusable="False">
            <v:IconButton Command="{Binding InverterInfoPanel.OpenLogCmd}" Image="{StaticResource LogBTN}" Content="{StaticResource TxtLog}" IconMargin="0,3,0,0" FontSize="11" FontFamily="{StaticResource MainFont}" ColorPalette="{StaticResource WhitePalette}" ToolTip="{StaticResource ToolTipLog}" Visibility="{Binding ComPort.IsSimulated, Converter={StaticResource InverseBooleanToVisibility}}" Focusable="False" IsTabStop="False"/>
            <v:IconButton Image="{StaticResource MonitorBTN}" Width="50" Content="{StaticResource TxtMonitor}" IconMargin="0,3,0,0" FontSize="11" FontFamily="{StaticResource MainFont}" ColorPalette="{StaticResource WhitePalette}" ToolTip="{StaticResource ToolTipMonitor}" Focusable="False" IsTabStop="False"/>
            <v:IconButton Command="{Binding InverterInfoPanel.OpenModbusCmd}" Image="{StaticResource HubBTN}" Content="{StaticResource TxtBtnModbus}" FontSize="11" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" ColorPalette="{StaticResource WhitePalette}" ToolTip="{StaticResource ToolTipOpenModbus}" Visibility="{Binding ComPort.IsSimulated, Converter={StaticResource InverseBooleanToVisibility}}" Focusable="False" IsTabStop="False"/>
            <v:IconButton Width="50"  Command="{Binding InverterInfoPanel.GetAllParametersCmd}" ToolTip="{StaticResource ToolTipGetAll}" Image="{StaticResource ImportBTN}" Content="{StaticResource TxtBtnGetFInv}" FontSize="11" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" ColorPalette="{StaticResource WhitePalette}" Visibility="{Binding ComPort.IsSimulated, Converter={StaticResource InverseBooleanToVisibility}}" Focusable="False" IsTabStop="False"/>
            <v:IconButton Width="50" Command="{Binding InverterInfoPanel.SendAllParametersCmd}" ToolTip="{StaticResource ToolTipSendAll}" Image="{StaticResource ExportBTN}" Content="{StaticResource TxtBtnSend2Inv}" FontSize="11" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" ColorPalette="{StaticResource WhitePalette}" Visibility="{Binding ComPort.IsSimulated, Converter={StaticResource InverseBooleanToVisibility}}" Focusable="False" IsTabStop="False"/>
            <v:IconButton Image="{StaticResource ResetBTN}" Width="50" Content="{StaticResource TxtBtnReset}" ToolTip="{StaticResource ToolTipReset}" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" FontSize="11"  ColorPalette="{StaticResource WhitePalette}" Focusable="False" IsTabStop="False"/>
            <v:IconButton Image="{StaticResource OpenBTN}" Width="50" Content="{StaticResource TxtOpen}" ToolTip="{StaticResource ToolTipOpenFile}" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" FontSize="11" ColorPalette="{StaticResource WhitePalette}" Focusable="False" IsTabStop="False"/>
            <v:IconButton Image="{StaticResource SaveBTN}" Width="50" Content="{StaticResource TxtSave}" ToolTip="{StaticResource ToolTipSaveFile}" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" FontSize="11" ColorPalette="{StaticResource WhitePalette}" Focusable="False" IsTabStop="False"/>
            <v:IconButton Command="{Binding InverterInfoPanel.CloseCmd}" Image="{StaticResource CloseBTN}" ToolTip="{StaticResource ToolTipClose}" Width="50" Content="{StaticResource TxtClose}" FontSize="11" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" ColorPalette="{StaticResource WhitePalette}" Focusable="False" IsTabStop="False"/>
            <Grid Margin="5" Width="12" Height="42" VerticalAlignment="Top" HorizontalAlignment="Right"/>
            <Image Source="{StaticResource NFOLogo}" Margin="5" Width="42" Height="42" VerticalAlignment="Top" HorizontalAlignment="Right"/>
        </StackPanel>

        <DockPanel Margin="0,50,0,0" Background="{StaticResource Milky}" KeyboardNavigation.TabNavigation="Cycle">
            <v:InverterInfoPanelV x:Name="InverterPanel" VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
            <Grid KeyboardNavigation.TabNavigation="Cycle">
                <v:ParamTabBarV VerticalAlignment="Top"/>
                <Frame Margin="16,32,0,0" Source="ParamFrameV.xaml" x:Name="pageFrame" KeyboardNavigation.TabNavigation="Cycle" NavigationUIVisibility="Hidden" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="0" Background="{StaticResource Milky}"/>
            </Grid>
        </DockPanel>

        <Image Source="{Binding InverterInfoPanel.Image, TargetNullValue={StaticResource FileIcon}}" Margin="30,35,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="64"/>
    </Grid>

    <ItemsControl ItemsSource="{Binding Path=ComPorts}" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="195,0,0,0">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel IsItemsHost="True" Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <v:TextStatusButton Status="{Binding Path=Status}" IsSelected="{Binding Path=IsSelected}" ColorPalette="{StaticResource DarkestGrayPalette}" Margin="1,0,1,0"  ColorPaletteFore="{StaticResource WhiteSolid}" Content="{Binding Path=Name}" FontSize="11" Command="{Binding Path=OpenComPortCmd}" Height="24" FontFamily="{StaticResource MainFont}" ToolTip="{Binding Path=FullName}"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

ParamFrame:

<UserControl x:Class="SinusManager.View.ParamFrameV"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" 
  xmlns:v="clr-namespace:SinusManager.View"
  xmlns:vm="clr-namespace:SinusManager.ViewModel"
  xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
  x:Name="pf"
  KeyboardNavigation.TabNavigation="Cycle">

<UserControl.Resources>
    <Style TargetType="TreeViewItem">
        <Setter Property="IsTabStop" Value="True"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
    </Style>
</UserControl.Resources>

<Grid KeyboardNavigation.TabNavigation="Cycle">
    <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" Margin="0,0,0,0" KeyboardNavigation.TabNavigation="Cycle">
        <i:Interaction.Behaviors>
            <v:BubbleScrollBehavior/>
        </i:Interaction.Behaviors>

        <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left" KeyboardNavigation.TabNavigation="Cycle">
            <Grid Width="311" Height="64" VerticalAlignment="Top" HorizontalAlignment="Left">
                <TextBlock Text="{Binding Name}" FontSize="14" FontFamily="{StaticResource MainFont}" FontWeight="Bold" Margin="6,16,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Height="50" Background="{StaticResource White}">
                    <v:IconButton IsTabStop="False" Command="{Binding GetParametersCmd}" Height="50" Width="55" Image="{StaticResource ImportBTN}" Content="{StaticResource TxtGetAll}" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" ColorPalette="{StaticResource MilkyPalette}" ToolTip="{StaticResource ToolTipGetParas}"/>
                    <v:IconButton IsTabStop="False" Command="{Binding SendParametersCmd}" Height="50" Width="55"  Image="{StaticResource ExportBTN}" Content="{StaticResource TxtSendAll}" IconMargin="0,3,0,0" FontFamily="{StaticResource MainFont}" ColorPalette="{StaticResource MilkyPalette}" ToolTip="{StaticResource ToolTipSendParas}"/>
                </StackPanel>
            </Grid>

            <TreeView Margin="0,16,0,0" KeyboardNavigation.TabNavigation="Cycle" Focusable="False" IsTabStop="False" ItemsSource="{Binding Nodes}" Background="{StaticResource Milky}" BorderThickness="0" ItemContainerStyle="{StaticResource TreeViewItemExpandedStyle}" HorizontalAlignment="Left" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                <TreeView.Resources>
                    <HierarchicalDataTemplate DataType="{x:Type vm:ParamTextNodeVM}" ItemsSource="{Binding Path=Nodes}">
                        <v:ParamNodeV Node="{Binding Path=NodeM}" Status="{Binding Status, Mode=TwoWay}" NameText="{Binding Path=Name}" UnitText="{Binding Path=Unit}" ValueText="{Binding Path=Value, Mode=TwoWay}" RangeText="{Binding Path=Range}" ValueTypeText="{Binding Path=ValueType}" DescriptionText="{Binding Path=Description}" ReadOnly="{Binding Path=ReadOnly}" GetParameter="{Binding GetParameterCmd}" SendParameter="{Binding SendParameterCmd}"/>
                    </HierarchicalDataTemplate>
                    <!--TabOrder="{Binding Path=TabOrder}"-->

                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding Path=IsOpen}"/>
                    </Style>

                    <HierarchicalDataTemplate DataType="{x:Type vm:ParamGroupNodeVM}" ItemsSource="{Binding Path=Nodes}" >
                        <v:ParamGroupNodeV Node="{Binding Path=NodeM}" IsTabStop="False" Status="{Binding Status, Mode=TwoWay}" NameText="{Binding Path=Name}" ChildCount="{Binding Path=ChildCount}" ReadOnly="{Binding Path=ReadOnly}" IsOpen="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType=TreeViewItem}, Mode=TwoWay}"/>
                    </HierarchicalDataTemplate>

                    <HierarchicalDataTemplate DataType="{x:Type vm:ParamComboNodeVM}" ItemsSource="{Binding Path=Nodes}">
                        <v:ParamComboNodeV Node="{Binding Path=NodeM}" IsTabStop="False" Status="{Binding Status, Mode=TwoWay}" NameText="{Binding Path=Name}" ComboBoxItems="{Binding Path=ComboBoxItems}" RangeText="{Binding Path=Range}" ValueTypeText="{Binding Path=ValueType}" DescriptionText="{Binding Path=Description}" SelectedItem="{Binding Path=SelectedItem}" ReadOnly="{Binding Path=ReadOnly}"  GetParameter="{Binding GetParameterCmd}" SendParameter="{Binding SendParameterCmd}"/>
                    </HierarchicalDataTemplate>
                </TreeView.Resources>
            </TreeView>
            <Grid Height="50"/>
        </StackPanel>
    </ScrollViewer>
</Grid>

ParamNode:

<UserControl x:Class="SinusManager.View.ParamNodeV"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
         xmlns:local="clr-namespace:SinusManager"
         xmlns:v="clr-namespace:SinusManager.View"
         xmlns:r="clr-namespace:SinusManager.Resources"
         xmlns:vm="clr-namespace:SinusManager.ViewModel"
         mc:Ignorable="d" 
         x:Name="pn"
         KeyboardNavigation.TabNavigation="Continue" Focusable="False" IsTabStop="False">

<StackPanel Background="{StaticResource Milky}">
    <Grid Focusable="False">
        <!--<v:IconButton ColorPalette="{StaticResource TransparentSolid}" ColorPaletteFore="{StaticResource WhiteToBluePalette}" Image="{StaticResource MiscExpanderBack}" IconMargin="0" Content="" VerticalAlignment="Top" Margin="0" HorizontalAlignment="Left" FontSize="1" Height="26" IconWidth="26" IconHeight="26"/>-->
        <v:IconButton Focusable="False" IsTabStop="False" ColorPalette="{StaticResource WhiteToBluePalette}" ImageBack="{StaticResource MiscExpanderBack}" ColorPaletteFore="{StaticResource BlackSolid}" IconMargin="0" Content="" VerticalAlignment="Top" Margin="0" HorizontalAlignment="Left" FontSize="1" Height="26" IconWidth="26" IconHeight="26"  Click="IconButton_Click">
            <v:IconButton.Image>
                <MultiBinding Converter="{StaticResource BivalentConverter}">
                    <Binding Path="IsOpen" RelativeSource="{RelativeSource AncestorType=UserControl, Mode=FindAncestor}"/>
                    <Binding Source="{StaticResource CollapseBTN}"/>
                    <Binding Source="{StaticResource ExpandBTN}"/>
                </MultiBinding>
            </v:IconButton.Image>
            <v:IconButton.ToolTip>
                <MultiBinding Converter="{StaticResource BivalentConverter}">
                    <Binding Path="IsOpen" RelativeSource="{RelativeSource AncestorType=UserControl, Mode=FindAncestor}"/>
                    <Binding Source="{StaticResource TxtCollapse}"/>
                    <Binding Source="{StaticResource TxtExpand}"/>
                </MultiBinding>
            </v:IconButton.ToolTip>
        </v:IconButton>

        <TextBox Text="{Binding Path=NameText, ElementName=pn}" FontFamily="{StaticResource MainFont}" VerticalContentAlignment="Center" HorizontalAlignment="Left" Margin="26,0,0,0" Height="26" VerticalAlignment="Bottom" IsReadOnly="True" IsTabStop="False" BorderThickness="0" Background="{StaticResource Milky}" FontWeight="Bold"/>
        <TextBox x:Name="ValueBox" VerticalContentAlignment="Center" PreviewTextInput="NumberValidationTextBox" FontFamily="{StaticResource MonoFont}" Text="{Binding Path=ValueText, ElementName=pn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Margin="130,0,0,0" VerticalAlignment="Top" Height="26" Width="92"
                  Focusable="True" IsTabStop="True" KeyboardNavigation.TabNavigation="Continue" IsReadOnly="{Binding Path=ReadOnly, ElementName=pn}">
            <!--TabIndex="{Binding Path=TabOrder, ElementName=pn}"-->
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="LostFocus">
                    <i:InvokeCommandAction Command="{Binding LostFocusCmd}" />
                </i:EventTrigger>
                <i:EventTrigger EventName="TextChanged">
                    <i:InvokeCommandAction Command="{Binding ValueChangedCmd}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <TextBox.Background>
                <MultiBinding Converter="{StaticResource MultiValuedConverter}">
                    <Binding Path="Status" ElementName="pn"/>
                    <Binding Source="{StaticResource White}"/>
                    <Binding Source="{StaticResource White}"/>
                    <Binding Source="{StaticResource TextBoxRed}"/>
                    <Binding Source="{StaticResource TextBoxRed}"/>
                </MultiBinding>
            </TextBox.Background>
        </TextBox>

        <v:ColoredImage IsTabStop="False" Image="{StaticResource LockIcon}" Margin="130,0,0,0" Height="20" Width="20" Color="{StaticResource LightGrayGray}" Visibility="{Binding Path=ReadOnly, ElementName=pn, Converter={StaticResource BooleanToVisibility}}"/>

        <TextBox IsTabStop="False" Text="{Binding Path=UnitText, ElementName=pn}" FontFamily="{StaticResource MainFont}" VerticalContentAlignment="Center" HorizontalAlignment="Left" Margin="222,0,0,0" VerticalAlignment="Bottom" Height="26" Width="73" IsReadOnly="True" BorderThickness="0" Background="{StaticResource Milky}"/>

        <!--Image="{StaticResource BoxIcon}"-->
        <v:ColoredImage IsTabStop="False" Width="20" Height="20" HorizontalAlignment="Right" Color="{StaticResource White}">
            <v:ColoredImage.Image>
                <MultiBinding Converter="{StaticResource MultiValuedConverter}">
                    <Binding Path="Status" ElementName="pn"/>
                    <Binding Source="{StaticResource CircleGUI}"/>
                    <Binding Source="{StaticResource CircleGUI}"/>
                    <Binding Source="{StaticResource TriangleGUI}"/>
                    <Binding Source="{StaticResource CircleGUI}"/>
                </MultiBinding>
            </v:ColoredImage.Image>
        </v:ColoredImage>
        <v:ColoredImage IsTabStop="False" Width="20" Height="20" HorizontalAlignment="Right">
            <v:ColoredImage.Color>
                <MultiBinding Converter="{StaticResource MultiValuedConverter}">
                    <Binding Path="Status" ElementName="pn"/>
                    <Binding Source="{StaticResource GreenLight}"/>
                    <Binding Source="{StaticResource YellowLight}"/>
                    <Binding Source="{StaticResource RedLight}"/>
                    <Binding Source="{StaticResource BlueLight}"/>
                </MultiBinding>
            </v:ColoredImage.Color>
            <v:ColoredImage.Image>
                <MultiBinding Converter="{StaticResource MultiValuedConverter}">
                    <Binding Path="Status" ElementName="pn"/>
                    <Binding Source="{StaticResource OkIcon}"/>
                    <Binding Source="{StaticResource WarningIcon}"/>
                    <Binding Source="{StaticResource ErrorIcon}"/>
                    <Binding Source="{StaticResource UnidentifiedIcon}"/>
                </MultiBinding>
            </v:ColoredImage.Image>
            <v:ColoredImage.ToolTip>
                <MultiBinding Converter="{StaticResource MultiValuedConverter}">
                    <Binding Path="Status" ElementName="pn"/>
                    <Binding Source="{StaticResource ToolTipOK}"/>
                    <Binding Source="{StaticResource ToolTipNotSynced}"/>
                    <Binding Source="{StaticResource ToolTipInvalid}"/>
                    <Binding Source="{StaticResource ToolTipUnidentified}"/>
                </MultiBinding>
            </v:ColoredImage.ToolTip>
        </v:ColoredImage>
    </Grid>

    <Grid Margin="0,2,0,0">
        <Image Margin="8, -4, 0, 0" Source="{StaticResource DownRight}" Width="24" Height="24" VerticalAlignment="Top" HorizontalAlignment="Left" Visibility="{Binding Path=IsOpen, ElementName=pn, Converter={StaticResource BooleanToVisibility}}"/>
        <StackPanel>
            <Border Width="263" Name="hej" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,0,0" BorderThickness="1" BorderBrush="{StaticResource Gray}" CornerRadius="5" Visibility="{Binding Path=IsOpen, ElementName=pn, Converter={StaticResource BooleanToVisibility}}">
                <Grid>
                    <WrapPanel Margin="0">
                        <TextBox Text="{Binding Path=DescriptionText, ElementName=pn}" IsTabStop="False" TextWrapping="Wrap" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="top" IsReadOnly="True" BorderThickness="0" Width="261" Background="{x:Null}" />
                        <TextBox Text="{StaticResource TxtValueType}" IsTabStop="False" HorizontalAlignment="Left" VerticalAlignment="top" IsReadOnly="True" BorderThickness="0" FontWeight="Bold" FontFamily="{StaticResource MainFont}" Background="{x:Null}"/>
                        <TextBox Text="{Binding Path=ValueTypeText, ElementName=pn}" IsTabStop="False" HorizontalAlignment="Left" VerticalAlignment="top" IsReadOnly="True" FontFamily="{StaticResource MainFont}" BorderThickness="0" Width="185" Background="{x:Null}"/>
                        <TextBox Text="{StaticResource TxtRange}" IsTabStop="False" HorizontalAlignment="Left" VerticalAlignment="top" IsReadOnly="True" BorderThickness="0" FontWeight="Bold" FontFamily="{StaticResource MainFont}" Background="{x:Null}"/>
                        <TextBox Text="{Binding Path=RangeText, ElementName=pn}" IsTabStop="False" HorizontalAlignment="Left" VerticalAlignment="top" IsReadOnly="True" FontFamily="{StaticResource MainFont}" BorderThickness="0" Width="210" Background="{x:Null}"/>
                        <Grid Height="62" Width="250"/>
                    </WrapPanel>
                    <v:IconButton IsTabStop="False" Margin="0,0,4,0" Command="{Binding Path=SendParameter, ElementName=pn}" HorizontalAlignment="Right" VerticalAlignment="Bottom" ColorPalette="{StaticResource MilkyPalette}" Foreground="Black" Content="{StaticResource BtnSendPara}" FontSize="9" FontFamily="{StaticResource MainFont}" Height="62" Image="{StaticResource ResourceKey=ExportBTN}"/>
                    <v:IconButton IsTabStop="False" Margin="4,0,0,0" Command="{Binding Path=GetParameter, ElementName=pn}" HorizontalAlignment="Left" VerticalAlignment="Bottom" ColorPalette="{StaticResource MilkyPalette}" Foreground="Black" Content="{StaticResource BtnGetPara}"  FontSize="9" FontFamily="{StaticResource MainFont}"  Height="62" Image="{StaticResource ResourceKey=ImportBTN}"/>
                </Grid>
            </Border>
            <Grid Height="3"/>
        </StackPanel>
    </Grid>
</StackPanel>

Control structure: Structure

The Problem: doesnt work


Solution

  • I added this part to within <TreeView.Resources> element. It fixed the problem.

                        <Style TargetType="{x:Type TreeViewItem}">
                            <Setter Property="IsExpanded" Value="{Binding Path=IsOpen}"/>
                            <Setter Property="IsTabStop" Value="True"/>
                            <Setter Property="Focusable" Value="False"/>
                            <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
                        </Style>