Welcome to our Microsoft Q&A platform!
I made a example,you can see my code:
ChildWindow:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.WindowStyle = WindowStyle.None;
this.Width = 200;
this.Height = 200;
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
if (MainWindow.timer.Enabled == false)
{
MainWindow.timer.Enabled = true;
}
}
private void Window_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
if (this.Width == 20)
{
this.Width = 200;
}
}
MainWindow
public partial class MainWindow : Window
{
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetParent")]
public extern static IntPtr SetParent(IntPtr childPtr, IntPtr parentPtr);
public static System.Timers.Timer timer = new System.Timers.Timer();
Window2 w2;
public MainWindow()
{
InitializeComponent();
w2 = new Window2();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
w2.Show();
WindowInteropHelper parentHelper = new WindowInteropHelper(this);
WindowInteropHelper childHelper = new WindowInteropHelper(w2);
SetParent(childHelper.Handle, parentHelper.Handle);
timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
timer.Interval = 100;
timer.Enabled = true;
}
public void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
{
this.Dispatcher.Invoke(() =>
{
if ((w2.Left - this.Left) < 10)
{
w2.Width = 20;
timer.Enabled = false;
}
});
}
}
Thanks.