【发布时间】:2014-08-05 08:56:33
【问题描述】:
我想知道是否可以将子窗口的移动能力限制为仅在父面板边界内移动?假设我通过单击按钮创建了一个子窗口:
<UserControl x:Class="ChildWindowTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Child="clr-namespace:ChildWindowTest"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" >
<Grid x:Name="LayoutRoot" >
<StackPanel Width="500" Height="500">
<Button Width="100" Height="25" Click="Button_Click" Content="Child Window"/>
</StackPanel>
</Grid>
</UserControl>
<controls:ChildWindow
x:Class="ChildWindowTest.ChildWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="400" Height="300" Title="ChildWindow1" >
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
</Grid>
</controls:ChildWindow>
我可以将生成的孩子在屏幕外向左、向右和向下移动(被剪掉)。我想避免这种情况,基本上设置一个允许移动子窗口的边界(在StackPanel边界内)
感谢您的任何建议..
【问题讨论】:
-
我没有在 ChildWindow 上尝试过,但
MouseDragElementBehavior和ConstrainToParentBounds="True"可能是一个快速简单的选择。
标签: c# silverlight mdichild childwindow mdiparent