gpt4 book ai didi

wpf - 将焦点设置到 WPF 中用户控件内的控件时未在 IDE 中显示 View

转载 作者:行者123 更新时间:2023-12-03 10:44:30 27 4
gpt4 key购买 nike

当我在构造函数中添加 this.IsVisibleChanged 时,它没有显示 View 。所以基本上我在 xaml View 中尝试使用 focus 方法,但效果不佳。所以我添加了这个并且运行良好。唯一的问题是设计 View 不是显示。它通过异常。

//Constructor
public LoginControl()
{
InitializeComponent();
this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(LoginControl_IsVisibleChanged);
}

void LoginControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue == true)
{
Dispatcher.BeginInvoke(
DispatcherPriority.ContextIdle,
new Action(delegate()
{
txtPassword.Focus();
}));
}
}

最佳答案

找到了答案

删除线

this.IsVisibleChanged += new DependencyPropertyChangedEventHandler
(LoginControl_IsVisibleChanged);

在 LoginControl 的开始标记中启用 IsVisibleChanged 属性并绑定(bind) LoginControl_IsVisibleChanged 方法。

将方法 LoginControl_IsVisibleChanged 的​​内容粘贴到里面

void LoginControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
{
if ((bool)e.NewValue == true)
{
Dispatcher.BeginInvoke(
DispatcherPriority.ContextIdle,
new Action(delegate()
{
txtPassword.Focus();
}));
}
}
}

关于wpf - 将焦点设置到 WPF 中用户控件内的控件时未在 IDE 中显示 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33162752/

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