首页 / C# / c# – 如何移动粘贴/捕捉wpf窗口
c# – 如何移动粘贴/捕捉wpf窗口
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 如何移动粘贴/捕捉wpf窗口,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2618字,纯文字阅读大概需要4分钟。
内容图文
当我移动一个“主”窗口时,我想移动两个或更多粘性窗口
我想做这样的事情
private void MainWindow_PreviewMouseMove(object sender, MouseEventArgs e) {
if (e.LeftButton == MouseButtonState.Pressed) {
this.DragMove();
foreach (var window in App.Current.Windows.OfType<Window>()) {
window.Move(); // move it
}
}
}
我想用这个解决方案来捕捉窗户
用于WPF的捕捉/粘性/磁性窗口
http://programminghacks.net/2009/10/19/download-snapping-sticky-magnetic-windows-for-wpf/
但我该怎么办呢?
编辑
在Gustavo Cavalcanti的回复之后,我做了一些想法.这是我的问题的粗略解决方案.
using System.Windows;
using System.Windows.Data;
namespace DragMoveForms
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1() {
this.InitializeComponent();
}
public Window1(Window mainWindow)
: this() {
var b = new Binding("Left");
b.Converter = new MoveLeftValueConverter();
b.ConverterParameter = mainWindow;
b.Mode = BindingMode.TwoWay;
b.Source = mainWindow;
BindingOperations.SetBinding(this, LeftProperty, b);
b = new Binding("Top");
b.Converter = new MoveTopValueConverter();
b.ConverterParameter = mainWindow;
b.Mode = BindingMode.TwoWay;
b.Source = mainWindow;
BindingOperations.SetBinding(this, TopProperty, b);
}
}
}
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace DragMoveForms
{
public class MoveLeftValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
// ok, this is simple, it only demonstrates what happens
if (value is double && parameter is Window) {
var left = (double)value;
var window = (Window)parameter;
// here i must check on which side the window sticks on
return left + window.ActualWidth;
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
return DependencyProperty.UnsetValue;
}
}
}
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace DragMoveForms
{
public class MoveTopValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
// ok, this is simple, it only demonstrates what happens
if (value is double && parameter is Window) {
var top = (double)value;
var window = (Window)parameter;
// here i must check on which side the window sticks on
return top;
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
return DependencyProperty.UnsetValue;
}
}
}
解决方法:
在窗口的左侧和顶部使用数据绑定.使用转换器根据主窗口确定右侧/顶部.然后只是担心移动主窗口,其他人将相应地移动.
内容总结
以上是互联网集市为您收集整理的c# – 如何移动粘贴/捕捉wpf窗口全部内容,希望文章能够帮你解决c# – 如何移动粘贴/捕捉wpf窗口所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。