Font size not setup for text - c#

this below is a chat window. the font size is not setup where to put this? for the chat text we do have font size for the send button
MinHeight="550" MinWidth="834"
Closed="Window_Closed" >
<Window.Resources>
<Style x:Key="SpeechOptionsStyle" TargetType="RadioButton">
<Setter Property="Margin" Value="2,8,0,0" />
</Style>
<Style x:Key="ChatButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="23" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Width" Value="150" />
<Setter Property="Margin" Value="0,5,0,0" />
</Style>
</Window.Resources>
<Grid>
<Grid.Background>
<LinearGradientBrush>
<GradientStop Color="LightSlateGray" Offset="0"/>
<GradientStop Color="Gainsboro" Offset="0.7"/>
<GradientStop Color="LightSlateGray" Offset="0.95"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="170" />
</Grid.ColumnDefinitions>
<ListBox Grid.Row="1" Grid.Column="0" x:Name="chatListBoxMsgs" Margin="10"
HorizontalContentAlignment="Stretch" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" >
<EventSetter Event="MouseDoubleClick"
Handler="chatListBoxMsgs_MouseDoubleClick" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Grid Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Margin="10"
Width="150">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox Grid.Row="0" x:Name="chatListBoxNames" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="150" />
<StackPanel Grid.Row="1" Margin="0,10,0,0"> <CheckBox Visibility="Hidden" x:Name="chatCheckBoxWhisper" Height="17" HorizontalAlignment="Left" Foreground="Black" FontSize="12" >Whisper Mode</CheckBox>
</StackPanel>
</Grid>
<TextBlock Visibility="Visible" Grid.Row="2" Grid.Column="0" x:Name="chatLabelWritingMsg"
Height="45" VerticalAlignment="Top" Foreground="MediumBlue"
TextWrapping="Wrap" Margin="10,0,0,0">Status</TextBlock>
<StackPanel Grid.Row="2" Grid.Column="1" Grid.RowSpan="2"
Orientation="Vertical" Margin="10,0" >
<Button x:Name="chatButtonConnect" Click="chatButtonConnect_Click"
Style="{StaticResource ChatButtonStyle}" >Connect</Button>
<Button x:Name="chatButtonDisconnect" Click="chatButtonDisconnect_Click"
Style="{StaticResource ChatButtonStyle}" >Disconnect</Button>
</StackPanel>
<Grid Grid.Row="3" Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" x:Name="chatTxtBoxType" Height="60"
VerticalAlignment="Top" Margin="10,0,5,5" TextWrapping="Wrap"
SpellCheck.IsEnabled="True" />
<Button Grid.Column="1" x:Name="chatButtonSend"
Click="chatButtonSend_Click" Height="60" VerticalAlignment="Top"
HorizontalAlignment="Right" Width="50" Margin="5,0,5,5"
FontSize="14">Send</Button>
</Grid>
</Grid>
</Window>
we have here the fontsize for the send button where do we put font ssize for the chat text it is defaulting to 8

From your code I think you want to set the font size of chatTxtBoxType. You can do it right in there (using an example size of 14):
<TextBox Grid.Column="0" x:Name="chatTxtBoxType" Height="60"
VerticalAlignment="Top" Margin="10,0,5,5" TextWrapping="Wrap"
SpellCheck.IsEnabled="True" FontSize="14"/>
Or using a style, like how you did for buttons (in that case, you might want to move some other properties to the style):
<Window.Resources>
<Style x:Key="ChatBoxStyle" TargetType="TextBox">
<Setter Property="FontSize" Value="14" />
</Style>
...
<TextBox Grid.Column="0" x:Name="chatTxtBoxType" Height="60"
VerticalAlignment="Top" Margin="10,0,5,5" TextWrapping="Wrap"
SpellCheck.IsEnabled="True" Style="{StaticResource ChatBoxStyle}"/>

Related

WPF: Content of round-cornered border not being round-cornered

I have a round-cornered border and I am trying to make its contents to be also round-cornered but my attempts are not working. Basically I am doing a kind of custom MessageBox but simpler, only with one image icon, a text and a button. No title bar. Image icon is changing depending on the type of message.
Stackpanel corners overlaps over border so border corners are not showing rounded.
ATTEMPT #1:
<Border x:Name="MyCustomMessageBox"
CornerRadius="5,5,5,5"
Grid.ZIndex="3"
Visibility="{Binding IsMessageBoxShown, Mode=TwoWay, Converter={StaticResource BoolToVis}}"
Width="auto" Height="auto"
HorizontalAlignment="Center"
VerticalAlignment="Center"
BorderBrush="DarkBlue" BorderThickness="1"
Background="White">
<Border.Effect>
<DropShadowEffect />
</Border.Effect>
<Grid Background="Blue">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" Background="WhiteSmoke">
<Grid>
<Image VerticalAlignment="Center" HorizontalAlignment="Left"
Source="/Common.MyImages;component/Images/Info.png"
Height="48" Width="48" Margin="20,10">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="/Common.MyImages;component/Images/Info.png"/>
<Style.Triggers>
<DataTrigger Binding="{Binding MsgType}" Value="1">
<Setter Property="Source" Value="/Common.MyImages;component/Images/Error.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Grid>
<TextBlock Width="280" Margin="0,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Left"
Background="Transparent" FontSize="12" TextWrapping="Wrap"><Run Text="This is a message"/>
</TextBlock>
</StackPanel>
<Button x:Name="btnCustomMessageBox" Grid.Row="1" Grid.Column="0"
Click="btnCustomMessageBox_Click"
HorizontalAlignment="Center" Margin="10" Width="80" Content="Ok" Visibility="Visible"/>
</Grid>
</Border>
ATTEMPT #2:
As explained here, I have tried also but without success.
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=MyCustomMessageBox}" />
</Grid.OpacityMask>
<!-- Here goes all the above border code -->
</Grid>
The following should solve your issue.
<Border x:Name="MyCustomMessageBox"
CornerRadius="5"
Visibility="{Binding IsMessageBoxShown, Mode=TwoWay, Converter={StaticResource BoolToVis}}"
Width="auto" Height="auto"
HorizontalAlignment="Center"
VerticalAlignment="Center"
BorderBrush="DarkBlue"
BorderThickness="1"
Background="blue">
<Border.Effect>
<DropShadowEffect />
</Border.Effect>
<Grid> <!-- removed the Background here. Only letting borders provide background. -->
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--
Added a border to fill the top part of the grid with the
whitesmoke color using a borderradius on the top.
Also note that the Background from the stackpanel was removed.
-->
<Border
Grid.Row="0" Grid.Column="0"
Name="mask"
Background="WhiteSmoke"
CornerRadius="5,5,0,0"
/>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
<Grid>
<Image VerticalAlignment="Center" HorizontalAlignment="Left"
Source="/Common.MyImages;component/Images/Info.png"
Height="48" Width="48" Margin="20,10">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="/Common.MyImages;component/Images/Info.png"/>
<Style.Triggers>
<DataTrigger Binding="{Binding MsgType}" Value="1">
<Setter Property="Source" Value="/Common.MyImages;component/Images/Error.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Grid>
<TextBlock Width="280" Margin="0,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Left"
Background="Transparent" FontSize="12" TextWrapping="Wrap"><Run Text="This is a message"/>
</TextBlock>
</StackPanel>
<Button x:Name="btnCustomMessageBox" Grid.Row="1" Grid.Column="0"
Click="btnCustomMessageBox_Click"
HorizontalAlignment="Center" Margin="10" Width="80" Content="Ok" Visibility="Visible"/>
</Grid>
</Border>

How can I make a border only on one/two sides?

I got to make 4 buttons near each other, I've done it by grid, but I've asked to add borders at only one/two sides (like in the next screenshot)
With borders
So far I've done that:
Without
The code:
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<Style TargetType="Button" x:Key="NavagtionButtons">
<Setter Property="Height" Value="100"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Background" Value="Black" />
<Setter Property="Foreground" Value="White" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Style="{StaticResource NavagtionButtons}" Grid.Row="0" Grid.Column="0" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="Assets/donut-icon.png" Stretch="None" />
<TextBlock Text="Donut" Margin="10,15,0,0" />
</StackPanel>
</Button.Content>
</Button>
<Button Style="{StaticResource NavagtionButtons}" Grid.Row="0" Grid.Column="1" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="Assets\coffee-icon.png" Stretch="None"/>
<TextBlock Text="Coffe" Margin="10,15,0,0" />
</StackPanel>
</Button.Content>
</Button>
<Button Style="{StaticResource NavagtionButtons}" Grid.Row="0" Grid.Column="2" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="Assets\schedule-icon.png" Stretch="None" />
<TextBlock Text="Schedule" Margin="10,15,0,0"/>
</StackPanel>
</Button.Content>
</Button>
<Button Style="{StaticResource NavagtionButtons}" Grid.Row="0" Grid.Column="3">
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="Assets\complete-icon.png" Stretch="None" />
<TextBlock Text="Complete" Margin="10,15,0,0"/>
</StackPanel>
</Button.Content>
</Button>
</Grid>
So how can I add borders only on the sides he showed?

How to override inline style in xaml

I have a TabControl which is bound to ViewModel. I want to set the margin of the auto generated TabPanel, but I am unable to do so, because I think the style is set inline via TabControl's implementation...
Here is my style...
<TabControl.Resources>
<Style TargetType="{x:Type TabPanel}">
<Setter Property="Margin" Value="14,0,0,0" />
</Style>
</TabControl.Resources>
and the resulting style using Visual Studio's Live Property Explorer is like this...
UPDATE 1:
Here is the XAML for ItemTemplate that generates the TabPanel itself:
<TabControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="150" />
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Grid.Column="0" Source="{Binding ImageUri}"
Height="25" Width="35" Margin="0,0,0,10" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding TestName}" TextAlignment="Center"
TextWrapping="Wrap" FontFamily="Open Sans" FontWeight="Regular" FontSize="14" />
</Grid>
</DataTemplate>
</TabControl.ItemTemplate>
You need to override the TabControl template to customize the appearance. In this case you will be responsible for designing template, but also will be able to customize it in a way you like.
Example template is taken from MSDN
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Width="500" Height="500">
<Window.Resources>
<Style TargetType="{x:Type TabControl}">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="SnapsToDevicePixels"
Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="#FFAAAAAA" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TabPanel x:Name="HeaderPanel"
Grid.Row="0"
Panel.ZIndex="1"
Margin="14,0,4,0"
IsItemsHost="True"
KeyboardNavigation.TabIndex="1"
Background="Transparent" />
<Border x:Name="Border"
Grid.Row="1"
BorderThickness="1"
CornerRadius="2"
KeyboardNavigation.TabNavigation="Local"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="{DynamicResource ContentAreaColorLight}" Offset="0" />
<GradientStop Color="{DynamicResource ContentAreaColorDark}" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
</Border.BorderBrush>
<ContentPresenter x:Name="PART_SelectedContentHost" Margin="4" ContentSource="SelectedContent" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<TabControl ItemsSource="{Binding Path=Items}">
<TabControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="150" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding .}" TextAlignment="Center"
TextWrapping="Wrap" FontFamily="Open Sans" FontWeight="Regular" FontSize="14" />
</Grid>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>

How to populate a ListView with composite UI elements?

I have a ListView like this:
<ListView x:Name="Thumbnails" HorizontalContentAlignment ="Center" VerticalContentAlignment="Top" Padding="0" Background ="#81AFD3" Grid.Row="6" Grid.Column="6" Grid.ColumnSpan="10" Grid.RowSpan="27" ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsSelected" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
Now, I would like to populate it with 5 elements. Each element is a a Grid that contains one image and two buttons. So I defined this Grid in UserControl.Resourceslike this:
</UserControl.Resources>
<Grid x:Key="ThumbnailElement">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Image Name="thumbImage" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="14" Grid.RowSpan="7" Source="/Assets/ImportAssets/Test.jpg"></Image>
<Button Name="slide_ON_OFF" Grid.Row="0" Grid.Column="10" Grid.ColumnSpan="4" Grid.RowSpan="4">
<Button.Template>
<ControlTemplate>
<Grid RenderTransformOrigin="0.5,0.5" x:Name="bg">
<Image Source="/MS_Show_Assets/ImportAssets/Visible_ON.png"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
<Button Name="fadein_ON_OFF" Grid.Row="3" Grid.Column="10" Grid.ColumnSpan="4" Grid.RowSpan="4">
<Button.Template>
<ControlTemplate>
<Grid RenderTransformOrigin="0.5,0.5" x:Name="bg">
<Image x:Name ="main_image" Source="/MS_Show_Assets/ImportAssets/Bulletpoint_ON.png"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</UserControl.Resources>
How would I do this, and only in XAML, without using code behind?
Use ContentControl to swap your views. Example:
<UserControl xmlns:Views="....View">
<UserControl.Resources>
<ControlTemplate x:Key="DefultTemplate">
<Views:DefultView/>
</ControlTemplate>
</UserControl.Resources>
<ListView x:Name="Thumbnails" HorizontalContentAlignment ="Center" VerticalContentAlignment="Top" Padding="0" Background ="#81AFD3" Grid.Row="6" Grid.Column="6" Grid.ColumnSpan="10" Grid.RowSpan="27" ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListView.ItemContainerStyle>
<Style TargetType="ContentControl">
<Setter Property="Template" Value="{StaticResource DefultTemplate}" />
</Style>
</ListView.ItemContainerStyle>
<ListItem Background="Red" Margin="5 5 5 5"/>
<ListItem Background="Red" Margin="5 5 5 5"/>
<ListItem Background="Red" Margin="5 5 5 5"/>
<ListItem Background="Red" Margin="5 5 5 5"/>
<ListItem Background="Red" Margin="5 5 5 5"/>
<ListItem Background="Red" Margin="5 5 5 5"/>
</ListView>
</UserControl>
DefultTemplate:
<UserControl ....>
<....>
</UserControl>
If we don't now the number of items, we can use:
<ListView ItemsSource="{Binding SomeCollection}" x:Name="Thumbnails" HorizontalContentAlignment ="Center" VerticalContentAlignment="Top" Padding="0" Background ="#81AFD3" Grid.Row="6" Grid.Column="6" Grid.ColumnSpan="10" Grid.RowSpan="27" ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListView.ItemContainerStyle>
<Style TargetType="ContentControl">
<Setter Property="Template" Value="{StaticResource DefultTemplate}" />
</Style>
</ListView.ItemContainerStyle>
</ListView>

C# Tab Index in TreeViewItem element

I have a simple TreeView, I'm not able to navigate in the TextBox with the focus. Do you have any suggestions???
I have updated the xaml code for give you more details. I hope this is helpful.
More Detail.
More Detail.
More Detail.
More Detail.
More Detail.
<StackPanel Orientation="Vertical" Margin="5">
<StackPanel Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Column1"/>
<ColumnDefinition Width="5" SharedSizeGroup="Column2"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
</Grid.RowDefinitions>
<GridSplitter Grid.Column="1" Grid.RowSpan="2147483647" HorizontalAlignment="Left" Width="5" VerticalContentAlignment="Stretch" IsTabStop="False"/>
<TextBlock Name="Number" Grid.Row="0" Grid.Column="0" Text="Number"/>
<TextBox x:Name="TxtNumber" Grid.Row="0" Grid.Column="2" Text="{Binding Number}" TabIndex="0"/>
<TextBlock Name="Name" Grid.Row="1" Grid.Column="0" Text="Name"/>
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding Name}" TabIndex="1"/>
</Grid>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="MyTree"/>
<TreeView x:Name="MyTree" BorderThickness="0" Grid.IsSharedSizeScope="True" KeyboardNavigation.TabNavigation="Continue">
<TreeView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Black" />
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeViewItem>
<TreeViewItem.Header>
<TextBlock Text="First Block" FontWeight="Bold"/>
</TreeViewItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Column1"/>
<ColumnDefinition Width="5" SharedSizeGroup="Column2"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
</Grid.RowDefinitions>
<GridSplitter Grid.Column="1" Grid.RowSpan="4" Width="5" HorizontalAlignment="Left" VerticalContentAlignment="Stretch" IsTabStop="False"/>
<TextBlock Grid.Row="0" Grid.Column="0" Text="A"/>
<CheckBox Grid.Row="0" Grid.Column="2" IsChecked="{Binding A}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="B"/>
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding B}" Width="200"/>
<TextBlock Name="PassBin" Grid.Row="2" Grid.Column="0" Text="C"/>
<ComboBox x:Name="CbxPassBin" Grid.Row="2" Grid.Column="2" ItemsSource="{Binding C}" SelectedValue="{Binding SelectedC}"/>
</Grid>
</TreeViewItem>
</TreeView>
</StackPanel>
</StackPanel>
TabIndex should be 1 and Focusable="true"
I found a solution, at least for my specific situation. The error was the ItemContainerStyle definition in the TreeView. Define the Window/UserControl resource's style for the TreeViewItem as below:
<Style TargetType="TreeViewItem">
<Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
<Setter Property="IsTabStop" Value="False"/>
</Style>

Categories

Resources