0
现在,我创建了一个MessageBox(一个自定义控件,不是用户控件)从Window继承,并为其提供ResourceDictionary中的样式。无法通过MouseLeftButtonDown拖动移动自定义消息框(自定义窗口)
像这样:
我希望我可以将移动通过的MouseLeftButtonDown在MessageBox和移动Blue TitleBar
,但它不符合我的方法工作。
这是我实现:
的.cs:
namespace Wpf.Controls
{
...
public MessageBoxModule()
{
...
SetupDragMoveCommand();
...
}
public static readonly DependencyProperty DragMoveCommandProperty =
DependencyProperty.Register(
"DragMoveCommand",
typeof(RoutedCommand),
typeof(MessageBoxModule));
public RoutedCommand DragMoveCommand
{
get { return (RoutedCommand)GetValue(DragMoveCommandProperty); }
set { SetValue(DragMoveCommandProperty, value); }
}
public void DragMoveCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
DragMove();
}
private void SetupDragMoveCommand()
{
DragMoveCommand = new RoutedCommand(
"DragMoveCommand",
typeof(MessageBoxModule));
CommandBindings.Add(
new CommandBinding(DragMoveCommand, DragMoveCommandExecuted));
}
...
}
.xmal:
<ResourceDictionary
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
<Style TargetType="{x:Type local:MessageBoxModule}">
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MessageBoxModule}">
<!--RootLayoutPanel-->
<DockPanel x:Name="RootLayoutPanel">
<Grid x:Name="TopSiderLayout">
<Rectangle x:Name="DragRectangle" Grid.ColumnSpan="2" StrokeThickness="0" Fill="#FF499A82" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{TemplateBinding DragMoveCommand}"/
</i:EventTrigger>
</i:Interaction.Triggers>
</Rectangle>
...