我有一个控件模板,用于定义自定义浮动文本框.
它由标签,作为文本框可视边界的边框和该边框内的文本框组成.
文本框本身的边框不可见.
我的问题是这样的:当自定义控件在UI中“标签”时,控件获取KeyboardFocus,但文本框本身没有.这会导致闪烁的光标不显示.
我需要知道如何将焦点从控件模板中的触发器传递到边框中包含的文本框,名为displayText.
我尝试使用FocusManager将displayText设置为聚焦元素,但这不起作用.
任何想法,想法或建议将不胜感激.如果您需要更多信息,请告诉我.
控制模板:
<Grid SnapsToDevicePixels="True" UseLayoutRounding="True"> <Grid.ColumnDeFinitions> <ColumnDeFinition Width="*"/> <ColumnDeFinition Width="Auto"/> </Grid.ColumnDeFinitions> <Label x:Name="floatingLabel" Template="{DynamicResource LabelControlTemplate1}" Content="{Binding LabelText,RelativeSource={RelativeSource Mode=TemplatedParent}}" IsHitTestVisible="False" Panel.ZIndex="2" Background="White" Height="15" VerticalContentAlignment="Center" Padding="3,3,0" HorizontalAlignment="Left" FontFamily="Segoe UI" FontSize="{Binding LabelFontSize,RelativeSource={RelativeSource TemplatedParent}}" Foreground="{DynamicResource FloatingLabelTextBox.Label.Foreground}" VerticalAlignment="Center"> <Label.Tag> <sys:Double>0.0</sys:Double> </Label.Tag> <Label.Margin> <MultiBinding Converter="{StaticResource floatingLabelMarginConverter}"> <Binding Path="Tag" RelativeSource="{RelativeSource Self}" /> <Binding ElementName="Border" Path="ActualHeight" /> </MultiBinding> </Label.Margin> </Label> <Border x:Name="Border" Height="{Binding TextBoxHeight,RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="3" SnapsToDevicePixels="True" Panel.ZIndex="0" VerticalAlignment="Bottom"> <Grid x:Name="GridContainer" Width="{Binding ElementName=Border,Path=ActualWidth}" Margin="10,0"> <TextBox x:Name="displayText" Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=FormattedPhoneNumber,StringFormat={}{0:(###)###-####},UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontWeight="{TemplateBinding FontWeight}" Foreground="{TemplateBinding Foreground}" Width="{Binding ElementName=Border,Path=ActualWidth}"> <TextBox.Template> <ControlTemplate targettype="{x:Type TextBox}"> <ScrollViewer x:Name="PART_ContentHost" HorizontalAlignment="Stretch" Margin="{TemplateBinding Padding}" Uid="ScrollViewer_1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </ControlTemplate> </TextBox.Template> </TextBox> </Grid> </Border> </Grid>
触发:
<Trigger Property="IsKeyboardFocused" Value="True"> <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=displayText}" /> </Trigger>
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。