gpt4 book ai didi

WPF 文本框焦点

转载 作者:行者123 更新时间:2023-12-04 06:52:05 24 4
gpt4 key购买 nike

我将焦点设置在这样的文本框上:

<DockPanel
Margin="0,0,0,0"
LastChildFill="True"
FocusManager.FocusedElement="{Binding ElementName=messengerTextToSend}">
<ListBox
x:Name="messengerLabelParticipants"
DockPanel.Dock="Top" Height="79" Margin="0,1,0,0" Padding="0"
Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0"
AllowDrop="True"
ItemsSource="{Binding Path=involvedUsers}" ItemTemplate="{StaticResource chatParticipants}" Tag="{Binding Path=chatSessionID}"
Drop="participantList_Drop" DragEnter="participantList_DragEnter" DragLeave="messengerLabelParticipants_DragLeave">
</ListBox>
<TextBox
x:Name="messengerTextToSend"
Focusable="True"
Margin="10,0,10,10"
DockPanel.Dock="Bottom" Height="100"
Tag="{Binding Path=.}"
KeyUp="messengerTextToSend_KeyUp"
Cursor="IBeam"
Style="{StaticResource messengerTextBoxSendText}"/>
<ScrollViewer
x:Name="messengerScroller"
Template="{DynamicResource ScrollViewerControlTemplate1}"
ScrollChanged="messengerScroller_ScrollChanged" Loaded="messengerScroller_Loaded"
Margin="0,10,0,10">
<ListBox
x:Name="messengerListMessages"
Margin="10,0,0,0" Padding="0"
Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Path=messages}" ItemTemplateSelector="{StaticResource messageTemplateSelector}">
</ListBox>
</ScrollViewer>
</DockPanel>

但是,当页面加载时,虽然文本框在视觉上看起来有焦点,但光标是静态的,我必须手动单击文本框或选项卡才能开始输入。我不确定我做错了什么,但我已经尝试了所有设置,包括在代码中设置它以使其正常工作。任何帮助将不胜感激。

最佳答案

将 FocusManager.FocusedElement 命令移动到 Window 元素。

<Window x:Class="MYClass.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="My Window"
FocusManager.FocusedElement="{Binding ElementName=messengerTextToSend}">
Height="400"
Width="600">
<DockPanel>
</DockPanel>
</Window>

看看这个 question对于用户控件。

关于WPF 文本框焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2966179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com