[英]Setting Focus to TextBox from Other UserControl inside a Canvas?
I am using a Canvas inside a Window, to make it like a MDI Application. 我在窗口内使用画布,使其像MDI应用程序一样。
The canvas will hold multiple UserControls which are Child Windows. 画布将包含多个作为子窗口的UserControl。
I am able to open a new UserControl inside the Canvas on the GotFocus event of some textbox. 我可以在某些文本框的GotFocus事件上的Canvas中打开一个新的UserControl。
But When I Click Enter or closes the new Window, I want to set the focus back to the old UserControl's next TextBox? 但是,当我单击Enter或关闭新窗口时,是否要将焦点设置回旧的UserControl的下一个TextBox? Which I am not able to achieve.
我无法实现。
I am using WPF with Caliburn Micro? 我在Caliburn Micro上使用WPF吗? Currently using EventAggreagator to open the new UserControl on GotFocus event of TextBox.
当前使用EventAggreagator在TextBox的GotFocus事件上打开新的UserControl。
I recently did something similar and the only thing I could come up with was to use the IEventAggregator
to publish a notification that a UserControl had closed, ie, 我最近做了类似的事情,唯一想到的就是使用
IEventAggregator
发布UserControl已关闭的通知,即
public class ControlClosedEvent
{
public ControlClosedEvent()
{
// can be an empty event for all intents and purposes
}
}
Whenever a UserControl closes, publish the event: 每当UserControl关闭时,都会发布事件:
_events.Publish( new ControlClosedEvent() );
And the consumers: 和消费者:
public partial class SomeView : UserControl, IHandle<ControlClosedEvent>
{
public void Handle( ControlClosedEvent message )
{
// ugly way of setting the text box as focused
SomeTextBox.Focus();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.