gpt4 book ai didi

WPF MVVM 禁用对 ContentControl 的关注(使用 Tab 键)

转载 作者:行者123 更新时间:2023-12-02 12:17:29 25 4
gpt4 key购买 nike

我有一个带有 ContentControl 绑定(bind)的窗口:

<ContentControl Content="{Binding CurrentViewModel}" />

我还有一个空用户控件绑定(bind)到 ContentControl:

<UserControl x:Class="UserControl1"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>

当我运行并按下选项卡键盘时,我会在内容控件周围看到一个虚线矩形。如何禁用此功能?

我尝试使用 Focusable="False"FocusVisualStyle="{x:Null}" 但没有成功...

最佳答案

您是否尝试过设置 IsTabStop="False",例如...

<ContentControl Height="200" Width="200" IsTabStop="False">
<ContentControl.Content>
<TextBox/>
</ContentControl.Content>
</ContentControl>

我建议你将它与这个技巧结合起来:

Loaded += (sender, e) =>
MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));

来自这个问题的答案:WPF and initial focus

关于WPF MVVM 禁用对 ContentControl 的关注(使用 Tab 键),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30692374/

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