我有一个完全透明的 WPF 窗口,没有包含几个按钮的标题栏。我怎样才能只拖动控件?
问问题
3265 次
1 回答
1
从这里下载 DragCanvas.cs,
它继承自Canvas
控件,给它一个透明的背景,它会为你完成这项工作。
您还可以将 DragCanvas 作为子项添加到另一个 DragCanvas 并同时移动多个控件
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication2"
Title="MainWindow" Height="350" Width="525">
<Grid>
<local:DragCanvas Background="Green">
<Grid Canvas.Left="48" Canvas.Top="57">
<Image Source="cursor_drag_arrow.png" Margin="233,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="33" Width="29"></Image>
<Button Content="Button" x:Name="btn" HorizontalAlignment="Left" Height="52" Margin="110,77,0,0" VerticalAlignment="Top" Width="124"/>
<Button Content="Button" x:Name="btn_Copy" HorizontalAlignment="Left" Height="52" Margin="10,10,0,0" VerticalAlignment="Top" Width="124"/>
</Grid>
</local:DragCanvas>
</Grid>
</Window>
这后面没有代码只需单击图像并拖动
和
于 2012-09-25T22:06:01.660 回答