Vibhesh Kaul
Vibhesh Kaul

Reputation: 2613

The Textbox doesn't show the blinking cursor on clicking or when it has focus

In the textboxes from the code below, the blinking cursor doesn't show even after i click the textbox or when it has focus.I'm posting this big a code because i think perhaps it's the parent element properties that are somehow interfering with the texboxes but I can't seem to find a solution for this. Can someone please help.

<Canvas Name="encounterTab" Style="{StaticResource canvasRecording}" Visibility="Hidden" Width="{DynamicResource {x:Static SystemParameters.FullPrimaryScreenWidthKey}}" FocusManager.IsFocusScope="True">
                <Grid Height="{DynamicResource {x:Static SystemParameters.FullPrimaryScreenHeightKey}}" Width="{DynamicResource {x:Static SystemParameters.FullPrimaryScreenWidthKey}}" Margin="0,0,0,0" FocusManager.IsFocusScope="True">
                    <DockPanel Style="{StaticResource screenTitleDock}" Grid.Row="0" VerticalAlignment="Top" >
                        <TextBlock Name="textBlock1"  Style="{StaticResource screenTitle}">ENCOUNTER DETAILS</TextBlock>
                    </DockPanel>
                    <Grid Style="{StaticResource gridRecording}" SizeChanged="MainGrid_SizeChanged" Name="gridEncDetails" FocusManager.IsFocusScope="True">
                        <Grid.LayoutTransform>
                            <ScaleTransform 
                        CenterX="0"
                        CenterY="0"
                        ScaleX="{Binding ElementName=myMainWindow, Path=ScaleValue}"
                        ScaleY="{Binding ElementName=myMainWindow, Path=ScaleValue}" />
                        </Grid.LayoutTransform>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="188*"></ColumnDefinition>
                            <ColumnDefinition Width="149*"></ColumnDefinition>
                            <ColumnDefinition Width="63*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition ></RowDefinition>
                            <RowDefinition ></RowDefinition>
                            <RowDefinition ></RowDefinition>
                            <RowDefinition ></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>

                        <Label x:Name="lblApptTime" Content="Time:" Grid.Column="0" Grid.Row="0"    />
                        <TextBox x:Name="txtTime" GotKeyboardFocus="txtApptTimeKeyBoadFocus" GotMouseCapture="txtApptTime_MouseClick" Grid.Column="1" Grid.Row="0" Width="149" LostFocus="txtApptTime_LostFocus" HorizontalAlignment="Left" MouseDoubleClick="txtApptTime_MouseDoubleClick" Margin="0,11" Height="38" GotTouchCapture="txtApptTime_GotTouchCapture" />
                        <ComboBox x:Name="ddlAmPm" VerticalContentAlignment="Center" Grid.Row="0" Grid.Column="2" Width="55" IsSynchronizedWithCurrentItem="True" Margin="0,10" HorizontalAlignment="Right" Height="38">
                            <ComboBoxItem>AM</ComboBoxItem>
                            <ComboBoxItem>PM</ComboBoxItem>
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid >
                                        <TextBlock Height="Auto"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Center" />
                                    </Grid>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                        <Label x:Name="lblNo" Content="No:" Grid.Column="0" Grid.Row="1" Margin="0,11" Height="38"  />
                        <TextBox x:Name="txtEncounterNumber" Grid.Column="1" Grid.Row="1"  KeyDown="txtEncounterNumber_KeyUp" TextChanged="txtEncounterNumber_TextChanged" HorizontalAlignment="Left" Width="212" Margin="0,10" Grid.ColumnSpan="2" Height="Auto" />
                        <Button x:Name="btnNext1" Grid.Row="2" Grid.ColumnSpan="3" Style="{StaticResource btnRec}" Click="btnNext1_Click" TouchUp="btnTouchNext1_Click" Margin="50,20,50,10" >
                            <Image Source="Assets/btnNext.png" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Button>
                    </Grid>
                </Grid>
</Canvas >

Note:- When i start typing the caret appears but disappears when i clear the textbox values.

Upvotes: 0

Views: 2403

Answers (1)

R.Rusev
R.Rusev

Reputation: 1141

It looks like you problem might comes from the ScaleTransform. If a TextBox is scaled to less then it's original size it's cursor disappears. This happens because the TextBox caret is with Width of 1 and when scaled down it becomes less then 1. So it's not visualized at all.

As a workaround make the minimal possible size as default so UI is only scaled up.

Another workaround it to create a custom caret like it's shown here WPF TextBox Inside ViewBox loses Cursor on resize

Upvotes: 2

Related Questions