【发布时间】:2014-08-01 15:48:01
【问题描述】:
我有 2 个 WPF 窗口,MainWindow 和 ChildWindow。我想在主窗口中点击一个事件来打开一个子窗口(我会将一些信息传递给子窗口)。在子窗口中,我希望 MainWindow 在子窗口中单击时更新。 工作流程: MainWindow --> TextBlock click --> create New ChildWindow params: x_coord, y_coord, line number --> 显示子窗口 子窗口 --> 在提交 btn 时单击 --> 将文本作为字符串发送回主窗口
public MainWindow()
{
InitializeComponent();
WorkspaceVersion.MouseLeftButtonDown += new MouseButtonEventHandler(WorkspaceVersion_MouseLeftButtonDown); // text block click event
}
// mouse left button down
private void WorkspaceVersion_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point position = e.GetPosition(WorkspaceVersion);
var i = Math.Round(position.Y/15); // line number
var commentWindow = new CommentWindow(position, i);
commentWindow.Show();
}
/////////////// child window /////////////
// probably need to create a custom event to raise, then register to in mainwindow
public CommentWindow()
{
InitializeComponent();
}
protected void SubmitButton_OnClick(object sender, EventArgs e)
{
string comment = new TextRange(CommentBox.Document.ContentStart, CommentBox.Document.ContentEnd).Text;
// raise event with custom args????
// main window should be listening for this event??
this.Close();
}
【问题讨论】: