问题
So I am working with WPF Infragistics XamDockManager
and PaneToolWindow
.
I am restyling the chrome of the PaneToolWindow
with a custom XamRibbonWindow
.
I have managed to do this successfully. When this is done though the PaneToolWindow
loses it's ability to be drug around.
The solution is to reimplement the dragging functionality (Both my assessment and also the recommendation from Infragistics). However, unfortunately for me, and all users of the Infragistics WPF toolkit, there is almost zero documentation and examples of how to do this. The one example that infragistics does provide is buggy to say the least.
The setup:
This is my custom Dock Manager
public class CustomDockManager : XamDockManager
{
protected override PaneToolWindow CreatePaneToolWindow()
{
return new CustomPaneToolWindow() as PaneToolWindow;
}
}
This is my custom PaneToolWindow
public class CustomPaneToolWindow : PaneToolWindow
{
private Point _MouseClickPoint { get; set; }
private Boolean _IsMouseDown { get; set; }
public CustomPaneToolWindow()
{
this.MouseLeftButtonDown += CustomPaneToolWindow_MouseLeftButtonDown;
}
private void CustomPaneToolWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this._IsMouseDown = true;
this._MouseClickPoint = e.GetPosition(this as UIElement);
}
else
{
this._IsMouseDown = false;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
//Need to move the window around here.
}
}
Now I tried simple and moved to complex.
First, I tried just doing something like this.
public Window _WindowOfCustomToolPaneWindow { get { return Window.GetWindow(this); } }
public CustomPaneToolWindow()
{
this._WindowOfCustomToolPaneWindow.MouseLeftButtonDown
+=CustomPaneToolWindow_MouseLeftButtonDown;
}
private void CustomPaneToolWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this._WindowOfCustomToolPaneWindow.DragMove();
}
You would think that this returns the window that is floating around and contains this
right? You'd be wrong. In fact it returns the parent window. This causes the DragMove()
call to send the child window flying off the screen.
So on to the next...
protected override void OnMouseMove(MouseEventArgs e)
{
Point cachedPoint = e.GetPosition(this as UIElement);
if (this._IsMouseDown && cachedPoint != this._MouseClickPoint)
{
Vector delta = Point.Subtract(this._MouseClickPoint, cachedPoint);
this.Left -= delta.X;
this.Top -= delta.Y;
this._MouseClickPoint = cachedPoint;
this._IsMouseDown = false;
}
}
This is a little more verbosely attempting to move the window around. Unfortunately it doesn't work either. I think it's adjusting the margins of the UserControl inside the window instead of moving the window itself.
I'm at a bit of a loss. The lack of support from Infragistics on the topic is disturbing to say the least.
Does anyone have any ideas on how to resolve this?
回答1:
Internally in the PaneToolWindow
drag event, Infragistics is looking for a UIElement named "PART_Caption"
By adding a border around my XamRibbonWindow
and giving it an x:Name="PART_Caption"
it solved the issue.
<Style TargetType="{x:Type igDock:PaneToolWindow}" x:Key="DockPTW">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDock:PaneToolWindow}">
<Border x:Name="PART_Caption" BorderThickness="4" Background="Red">
<igRibbon:RibbonWindowContentHost>
<igRibbon:RibbonWindowContentHost.Ribbon>
<igRibbon:XamRibbon x:Name="MAIN_RIBBON" DockPanel.Dock="Top">
</igRibbon:XamRibbon>
</igRibbon:RibbonWindowContentHost.Ribbon>
<Grid Width="1000" Height="500">
</Grid>
</igRibbon:RibbonWindowContentHost>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
来源:https://stackoverflow.com/questions/31387161/infragistics-panetoolwindow-window-dragmove-spooky-results