i have problems wiht the SetDragRegion Method I start the debugger all works fine captionsregion and tabviewitem are not draggable but when i maximize my window i can drag move with the tabviewitem and loose the ability to tearing the tabviewitem out of the window if i add a new tab the dragregion becomes corrected. but thats not the way i want
My TabViewControl VisualTree
<Grid>
<TabView x:Name="MyTabView" Background="Transparent" AddTabButtonClick="MyTabView_AddTabButtonClick" TabCloseRequested="MyTabView_TabCloseRequested">
<!--Definiert den Start von Links nach Rechts-->
<TabView.TabStripHeader>
<Border x:Name="MyCustomMenuRegion" MinWidth="0" Background="Transparent" IsHitTestVisible="False"/>
</TabView.TabStripHeader>
<!--Default Home Tab-->
<TabViewItem Header="Home" Background="Transparent" IsClosable="False" MaxHeight="40" MaxWidth="50">
</TabViewItem>
<!--Definiert den Ende von Rechts nach Links-->
<TabView.TabStripFooter>
<Border x:Name="CustomDragRegion" MinWidth="0" Background="Transparent" IsHitTestVisible="False" SizeChanged="CustomDragRegion_SizeChanged"/>
</TabView.TabStripFooter>
</TabView>
</Grid>
my UserWindow(MainWindow) VisualTree
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" x:Name="TitleBarRegion"/>
<RowDefinition Height="*" x:Name="ContentRegion"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" x:Name="ControlRegion"/>
</Grid.ColumnDefinitions>
<myUICrl:MyTitleRegionControl x:Name="MyTitleRegion" Grid.Row="0" Grid.Column="0" Canvas.ZIndex="0"/>
<myUICrl:MyCaptionsRegionControl x:Name="MyCaptionsRegion" Grid.Row="0" Grid.Column="1" Canvas.ZIndex="2" HorizontalAlignment="Right"/>
<myUICrl:MyTabViewControl x:Name="MyTabView" Grid.Row="0" Grid.Column="0" Canvas.ZIndex="1"/>
</Grid>
Code behind: alle methods include SertDragRegion
private void MyUserWindow_SizeChanged(object sender, WindowSizeChangedEventArgs args)
{
this.MyCaptionsRegion.OnWindowStateChanged();
if (this.MyTitleRegion.XamlRoot != null)
{ SetRegionsForCustomTitleBar(); }
}
internal void SetRegionsForCustomTitleBar()
{
double scale = this.MyTitleRegion.XamlRoot.RasterizationScale;
// Set the Width of TitleBar
SetTitleBarWidth(this.AppWindow, this.MyTitleRegion, scale);
// Set the draggable Area/Region of TitleBar
SetDraggableArea(this.AppWindow, this.MyTabView, scale);
// Set the non-draggable Area/Region of CaptionsButton
SetNonDraggableRegion(this.AppWindow, this.MyCaptionsRegion, scale);
}
private void SetTitleBarWidth(AppWindow myAppWindow, MyTitleRegionControl myTitleRegion, double scale)
{
myTitleRegion.GetHeaderDefinition().Width = new GridLength(myAppWindow.TitleBar.LeftInset / scale);
myTitleRegion.GetFooterDefinition().Width = new GridLength(myAppWindow.TitleBar.RightInset / scale);
}
private void SetDraggableArea(AppWindow myAppWindow, MyTabViewControl myTabView, double scale)
{
Border myCustomDragRegion = myTabView.GetCustomDragRegion();
GeneralTransform customDragRegionTransform = myCustomDragRegion.TransformToVisual(null);
Rect customDragRegionBounds = customDragRegionTransform.TransformBounds(new Rect(0, 0, myCustomDragRegion.ActualWidth, myCustomDragRegion.ActualHeight));
RectInt32 customDragRegionRect = GetRect(customDragRegionBounds, scale);
Trace.WriteLine($"[SetDraggableArea] Bounds: X={customDragRegionBounds.X}, Y={customDragRegionBounds.Y}, W={customDragRegionBounds.Width}, H={customDragRegionBounds.Height}");
Trace.WriteLine($"[SetDraggableArea] Scaled Rect: X={customDragRegionRect.X}, Y={customDragRegionRect.Y}, W={customDragRegionRect.Width}, H={customDragRegionRect.Height}");
myAppWindow.TitleBar.SetDragRectangles(GetRectArray(customDragRegionRect));
}
private void SetNonDraggableRegion(AppWindow myAppWindow, MyCaptionsRegionControl myCaptionsRegion, double scale)
{
GeneralTransform captionsRegionTransform = myCaptionsRegion.TransformToVisual(null);
Rect captionsRegionBounds = captionsRegionTransform.TransformBounds(new Rect(0, 0, myCaptionsRegion.ActualWidth, myCaptionsRegion.ActualHeight));
RectInt32 captionsRegionRect = GetRect(captionsRegionBounds, scale);
InputNonClientPointerSource nonClientInputSrc = InputNonClientPointerSource.GetForWindowId(myAppWindow.Id);
nonClientInputSrc.SetRegionRects(NonClientRegionKind.Passthrough, GetRectArray(captionsRegionRect));
}
private RectInt32 GetRect(Rect bounds, double scale)
{
return new RectInt32
(
_X: (int)Math.Round(bounds.X * scale),
_Y: (int)Math.Round(bounds.Y * scale),
_Width: (int)Math.Round(bounds.Width * scale),
_Height: (int)Math.Round(bounds.Height * scale)
);
}
private RectInt32[] GetRectArray(RectInt32 rect)
{
return new RectInt32[] { rect };
}
i also testet if the size correct calculated Start: [SetDraggableArea] Bounds: X=97, Y=0, W=1327, H=40 [SetDraggableArea] Scaled Rect: X=97, Y=0, W=1327, H=40
After Maximizing: [SetDraggableArea] Bounds: X=97, Y=0, W=1823, H=40 [SetDraggableArea] Scaled Rect: X=97, Y=0, W=1823, H=40
After restoring back: [SetDraggableArea] Bounds: X=97, Y=0, W=1327, H=40 [SetDraggableArea] Scaled Rect: X=97, Y=0, W=1327, H=40
i think the problem exist inside the SetDraggableArea Method But i dont know what
if anybody know wahts my fault is please tell me
EDIT: i fix it by Myself i remove the Line SetRegionsForCurstomTitleBar from MyUserWindow_SizeChanged Event Method
private void MyUserWindow_SizeChanged(object sender, WindowSizeChangedEventArgs args)
{
this.MyCaptionsRegion.OnWindowStateChanged();
}
I give the CustomDragRegion Control of my TabStripFooter a size Changed event without the 50 ms Task.Delay the problem still exist with adding the 50 ms delay it fix the problem
private async void CustomDragRegion_SizeChanged(object sender, SizeChangedEventArgs args)
{
await Task.Delay(50);
ManageWindows.GetUserWindow().SetRegionsForCustomTitleBar();
}
i wont delete the post maybe someone has the same problem and here is the resulution
i have problems wiht the SetDragRegion Method I start the debugger all works fine captionsregion and tabviewitem are not draggable but when i maximize my window i can drag move with the tabviewitem and loose the ability to tearing the tabviewitem out of the window if i add a new tab the dragregion becomes corrected. but thats not the way i want
My TabViewControl VisualTree
<Grid>
<TabView x:Name="MyTabView" Background="Transparent" AddTabButtonClick="MyTabView_AddTabButtonClick" TabCloseRequested="MyTabView_TabCloseRequested">
<!--Definiert den Start von Links nach Rechts-->
<TabView.TabStripHeader>
<Border x:Name="MyCustomMenuRegion" MinWidth="0" Background="Transparent" IsHitTestVisible="False"/>
</TabView.TabStripHeader>
<!--Default Home Tab-->
<TabViewItem Header="Home" Background="Transparent" IsClosable="False" MaxHeight="40" MaxWidth="50">
</TabViewItem>
<!--Definiert den Ende von Rechts nach Links-->
<TabView.TabStripFooter>
<Border x:Name="CustomDragRegion" MinWidth="0" Background="Transparent" IsHitTestVisible="False" SizeChanged="CustomDragRegion_SizeChanged"/>
</TabView.TabStripFooter>
</TabView>
</Grid>
my UserWindow(MainWindow) VisualTree
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" x:Name="TitleBarRegion"/>
<RowDefinition Height="*" x:Name="ContentRegion"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" x:Name="ControlRegion"/>
</Grid.ColumnDefinitions>
<myUICrl:MyTitleRegionControl x:Name="MyTitleRegion" Grid.Row="0" Grid.Column="0" Canvas.ZIndex="0"/>
<myUICrl:MyCaptionsRegionControl x:Name="MyCaptionsRegion" Grid.Row="0" Grid.Column="1" Canvas.ZIndex="2" HorizontalAlignment="Right"/>
<myUICrl:MyTabViewControl x:Name="MyTabView" Grid.Row="0" Grid.Column="0" Canvas.ZIndex="1"/>
</Grid>
Code behind: alle methods include SertDragRegion
private void MyUserWindow_SizeChanged(object sender, WindowSizeChangedEventArgs args)
{
this.MyCaptionsRegion.OnWindowStateChanged();
if (this.MyTitleRegion.XamlRoot != null)
{ SetRegionsForCustomTitleBar(); }
}
internal void SetRegionsForCustomTitleBar()
{
double scale = this.MyTitleRegion.XamlRoot.RasterizationScale;
// Set the Width of TitleBar
SetTitleBarWidth(this.AppWindow, this.MyTitleRegion, scale);
// Set the draggable Area/Region of TitleBar
SetDraggableArea(this.AppWindow, this.MyTabView, scale);
// Set the non-draggable Area/Region of CaptionsButton
SetNonDraggableRegion(this.AppWindow, this.MyCaptionsRegion, scale);
}
private void SetTitleBarWidth(AppWindow myAppWindow, MyTitleRegionControl myTitleRegion, double scale)
{
myTitleRegion.GetHeaderDefinition().Width = new GridLength(myAppWindow.TitleBar.LeftInset / scale);
myTitleRegion.GetFooterDefinition().Width = new GridLength(myAppWindow.TitleBar.RightInset / scale);
}
private void SetDraggableArea(AppWindow myAppWindow, MyTabViewControl myTabView, double scale)
{
Border myCustomDragRegion = myTabView.GetCustomDragRegion();
GeneralTransform customDragRegionTransform = myCustomDragRegion.TransformToVisual(null);
Rect customDragRegionBounds = customDragRegionTransform.TransformBounds(new Rect(0, 0, myCustomDragRegion.ActualWidth, myCustomDragRegion.ActualHeight));
RectInt32 customDragRegionRect = GetRect(customDragRegionBounds, scale);
Trace.WriteLine($"[SetDraggableArea] Bounds: X={customDragRegionBounds.X}, Y={customDragRegionBounds.Y}, W={customDragRegionBounds.Width}, H={customDragRegionBounds.Height}");
Trace.WriteLine($"[SetDraggableArea] Scaled Rect: X={customDragRegionRect.X}, Y={customDragRegionRect.Y}, W={customDragRegionRect.Width}, H={customDragRegionRect.Height}");
myAppWindow.TitleBar.SetDragRectangles(GetRectArray(customDragRegionRect));
}
private void SetNonDraggableRegion(AppWindow myAppWindow, MyCaptionsRegionControl myCaptionsRegion, double scale)
{
GeneralTransform captionsRegionTransform = myCaptionsRegion.TransformToVisual(null);
Rect captionsRegionBounds = captionsRegionTransform.TransformBounds(new Rect(0, 0, myCaptionsRegion.ActualWidth, myCaptionsRegion.ActualHeight));
RectInt32 captionsRegionRect = GetRect(captionsRegionBounds, scale);
InputNonClientPointerSource nonClientInputSrc = InputNonClientPointerSource.GetForWindowId(myAppWindow.Id);
nonClientInputSrc.SetRegionRects(NonClientRegionKind.Passthrough, GetRectArray(captionsRegionRect));
}
private RectInt32 GetRect(Rect bounds, double scale)
{
return new RectInt32
(
_X: (int)Math.Round(bounds.X * scale),
_Y: (int)Math.Round(bounds.Y * scale),
_Width: (int)Math.Round(bounds.Width * scale),
_Height: (int)Math.Round(bounds.Height * scale)
);
}
private RectInt32[] GetRectArray(RectInt32 rect)
{
return new RectInt32[] { rect };
}
i also testet if the size correct calculated Start: [SetDraggableArea] Bounds: X=97, Y=0, W=1327, H=40 [SetDraggableArea] Scaled Rect: X=97, Y=0, W=1327, H=40
After Maximizing: [SetDraggableArea] Bounds: X=97, Y=0, W=1823, H=40 [SetDraggableArea] Scaled Rect: X=97, Y=0, W=1823, H=40
After restoring back: [SetDraggableArea] Bounds: X=97, Y=0, W=1327, H=40 [SetDraggableArea] Scaled Rect: X=97, Y=0, W=1327, H=40
i think the problem exist inside the SetDraggableArea Method But i dont know what
if anybody know wahts my fault is please tell me
EDIT: i fix it by Myself i remove the Line SetRegionsForCurstomTitleBar from MyUserWindow_SizeChanged Event Method
private void MyUserWindow_SizeChanged(object sender, WindowSizeChangedEventArgs args)
{
this.MyCaptionsRegion.OnWindowStateChanged();
}
I give the CustomDragRegion Control of my TabStripFooter a size Changed event without the 50 ms Task.Delay the problem still exist with adding the 50 ms delay it fix the problem
private async void CustomDragRegion_SizeChanged(object sender, SizeChangedEventArgs args)
{
await Task.Delay(50);
ManageWindows.GetUserWindow().SetRegionsForCustomTitleBar();
}
i wont delete the post maybe someone has the same problem and here is the resulution
Share Improve this question edited Mar 24 at 8:13 Pain Nncera asked Mar 21 at 22:57 Pain NnceraPain Nncera 436 bronze badges1 Answer
Reset to default 0This is a community wiki to help people with the same problem.
If you are using TabView
and the Custom titlebar position is incorrect after maximizing it, you could try to update the layout and size with delaying in the Sizechanged event of TabView
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744330362a4568857.html
评论列表(0条)