Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document tabs dragged like in XBAP #1468

Open
TheCamel opened this issue Mar 25, 2019 · 5 comments
Open

Document tabs dragged like in XBAP #1468

TheCamel opened this issue Mar 25, 2019 · 5 comments

Comments

@TheCamel
Copy link

@TheCamel TheCamel commented Mar 25, 2019

Hi, I have a strange behaviour but only in XBAP mode. The same application and code is working well in my WPF container.

in XBAP, when i click on document tabs, sometimes the tab follow the mouse (and often undock) like if it was dragged by the user. I debug the code and it seems that MouseUp is not fired...then the move_event consider we drag it....

to overcome it I increase the delta by five....because i can't find out why there is not OnMouseLeftButtonUp event

LayoutDocumentTabItem ==>OnMouseMove
if( Math.Abs( ptMouseMove.X - _mouseDownPoint.X ) > SystemParameters.MinimumHorizontalDragDistance*5 ||......

@TheCamel
Copy link
Author

@TheCamel TheCamel commented Mar 26, 2019

I solved the issue....removed specific mouse events and reorded a few lines in LayoutDocumentTabItem

protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Middle)
{
if (LayoutItem.CloseCommand.CanExecute(null))
LayoutItem.CloseCommand.Execute(null);
}
if (e.ChangedButton == MouseButton.Left)
{
var layoutDocument = Model as LayoutDocument;
if ((layoutDocument != null) && !layoutDocument.CanMove)
return;

			if (e.ClickCount == 1)
			{
				_mouseDownPoint = e.GetPosition(this);
				_isMouseDown = true;
			}
			e.Handled = true;
		}
		base.OnMouseDown(e);
	}

	protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
	{
		base.OnMouseMove(e);

		if (_isMouseDown)
		{
			Point ptMouseMove = e.GetPosition(this);

			if (Math.Abs(ptMouseMove.X - _mouseDownPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
				Math.Abs(ptMouseMove.Y - _mouseDownPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
			{
				this.UpdateDragDetails();
				this.CaptureMouse();
				_isMouseDown = false;
			}
		}

		if (this.IsMouseCaptured)
		{
			var mousePosInScreenCoord = this.PointToScreenDPI(e.GetPosition(this));
			if (!_parentDocumentTabPanelScreenArea.Contains(mousePosInScreenCoord))
			{
				this.StartDraggingFloatingWindowForContent();
			}
			else
			{
				int indexOfTabItemWithMouseOver = _otherTabsScreenArea.FindIndex(r => r.Contains(mousePosInScreenCoord));
				if (indexOfTabItemWithMouseOver >= 0)
				{
					var targetModel = _otherTabs[indexOfTabItemWithMouseOver].Content as LayoutContent;
					var container = this.Model.Parent as ILayoutContainer;
					var containerPane = this.Model.Parent as ILayoutPane;

					if ((containerPane is LayoutDocumentPane) && !((LayoutDocumentPane)containerPane).CanRepositionItems)
						return;
					if ((containerPane.Parent != null) && (containerPane.Parent is LayoutDocumentPaneGroup) && !((LayoutDocumentPaneGroup)containerPane.Parent).CanRepositionItems)
						return;

					var childrenList = container.Children.ToList();
					containerPane.MoveChild(childrenList.IndexOf(Model), childrenList.IndexOf(targetModel));
					this.Model.IsActive = true;
					_parentDocumentTabPanel.UpdateLayout();
					this.UpdateDragDetails();
				}
			}
		}
	}

	protected override void OnMouseUp(MouseButtonEventArgs e)
	{
		base.OnMouseUp(e);

		if (IsMouseCaptured)
			ReleaseMouseCapture();

		_isMouseDown = false;
		Model.IsActive = true;

		e.Handled = true;
	}

	//protected override void OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)
	//{
	//	if (IsMouseCaptured)
	//		ReleaseMouseCapture();
	//	_isMouseDown = false;

	//	base.OnMouseLeftButtonUp(e);
	//	e.Handled = true;
	//}

	protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
	{
		base.OnMouseLeave(e);
		_isMouseDown = false;
	}

	protected override void OnMouseEnter(MouseEventArgs e)
	{
		base.OnMouseEnter(e);
		_isMouseDown = false;
	}

	//protected override void OnMouseDown(MouseButtonEventArgs e)
	//{
	//	if (e.ChangedButton == MouseButton.Middle)
	//	{
	//		if (LayoutItem.CloseCommand.CanExecute(null))
	//			LayoutItem.CloseCommand.Execute(null);
	//	}

	//	base.OnMouseDown(e);
	//}
@XceedBoucherS
Copy link
Collaborator

@XceedBoucherS XceedBoucherS commented Apr 2, 2019

Hi,
Is this issue still present in the latest v3.8 version available for free for 45 days here : https://xceed.com/xceed-toolkit-plus-for-wpf/ ?

@TheCamel
Copy link
Author

@TheCamel TheCamel commented Apr 2, 2019

Hi,
yes, stil present (the code is the same in LayoutDocumentTabItem). - I tried the download.
btw, i am quite sure was not there in free 3.0
bye

@XceedBoucherS
Copy link
Collaborator

@XceedBoucherS XceedBoucherS commented Apr 2, 2019

Hi,
Can you submit a sample project running in XBAP mode so we can test the same scenario as the one you are getting ? Does it happens all the time or just some times ?
Thank you.

@TheCamel
Copy link
Author

@TheCamel TheCamel commented Apr 2, 2019

Hi,
no, I can't provide source because too big with services, db ...
not allways but quite often
we are using a user control hosted in WPF or XBAP container, code below but quite sure a simple doc collection is enough ??

<Grid >
	<Grid.RowDefinitions>
		<RowDefinition Height="*"></RowDefinition>
		<RowDefinition Height="Auto"></RowDefinition>
	</Grid.RowDefinitions>

	<!--DOCKING-->

	<avalonDock:DockingManager x:Name="dockManager" Grid.Row="0" Background="Transparent"
			AnchorablesSource="{Binding Tools}"  
			DocumentsSource="{Binding Documents}"
			IsEnabled="{Binding Path=IsEnabled, ElementName=FooterView, Mode=OneWay}"
			ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={x:Static Converters:ActiveDocumentConverter.Instance}}"
			Behaviors:LayoutSerializerBehavior.LoadLayoutCommand="{Binding ADLayout.LoadLayoutCommand}"
			Behaviors:LayoutSerializerBehavior.SaveLayoutCommand="{Binding ADLayout.SaveLayoutCommand}">

		<avalonDock:DockingManager.Theme>
            <Themes:AvalonMetroTheme />
		</avalonDock:DockingManager.Theme>

        <avalonDock:DockingManager.DocumentHeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" x:Name="toto" Background="Transparent">
                    <TextBlock Text="{Binding Title}" TextTrimming="CharacterEllipsis"/>
                </StackPanel>
            </DataTemplate>
        </avalonDock:DockingManager.DocumentHeaderTemplate>

        <avalonDock:DockingManager.LayoutItemContainerStyleSelector>
			<Selectors:PanesStyleSelector>
				<Selectors:PanesStyleSelector.ToolStyle>
					<Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}">
						<Setter Property="CanClose" Value="false"/>
						<Setter Property="CanFloat" Value="false"/>
                        <Setter Property="CanHide" Value="false"/>
                        <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
						<Setter Property="Title" Value="{Binding Model.DisplayName}"/>
						<Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
						<Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/>
						<Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
					</Style>
				</Selectors:PanesStyleSelector.ToolStyle>
				<Selectors:PanesStyleSelector.DocumentStyle>
					<Style TargetType="{x:Type avalonDock:LayoutItem}">
						<Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
						<Setter Property="Title" Value="{Binding Model.DisplayName}"/>
						<Setter Property="ToolTip" Value="{Binding Model.DisplayName}"/>
						<Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
						<Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/>
                        <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
                    </Style>
				</Selectors:PanesStyleSelector.DocumentStyle>
			</Selectors:PanesStyleSelector>
		</avalonDock:DockingManager.LayoutItemContainerStyleSelector>

		<avalonDock:LayoutRoot>
			<avalonDock:LayoutPanel Orientation="Vertical">
                
                <avalonDock:LayoutDocumentPaneGroup>
                    <avalonDock:LayoutDocumentPane/>
				</avalonDock:LayoutDocumentPaneGroup>
                
				<avalonDock:LayoutAnchorablePaneGroup DockHeight="250">
					<avalonDock:LayoutAnchorablePane Name="ToolsPane" DockHeight="250" />
				</avalonDock:LayoutAnchorablePaneGroup>
				
			</avalonDock:LayoutPanel>
		</avalonDock:LayoutRoot>
	</avalonDock:DockingManager>

	<!--FOOTER-->
	<Views:FooterView x:Name="FooterView" Grid.Row="1" />

</Grid>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.