Я пытаюсь создать какое-то окно или набор инструментов, которые можно перетаскивать на часть заголовка, как любое окно.По некоторым причинам, это, кажется, не работает для меня.Заголовок перемещается, но часть тела остается неподвижной.
Вот мой код:
BehaviorCollection behaviorCollection = Interaction.GetBehaviors(this._explorerHeader);
MouseDragElementBehavior mouseDragBehavior = new MouseDragElementBehavior { ConstrainToParentBounds = false };
mouseDragBehavior.Dragging += (s1, e1) =>
{
Canvas.SetLeft(this._explorerBody, (Double)_explorerHeader.GetValue(Canvas.LeftProperty));
Canvas.SetTop(this._explorerBody, ((Double)_explorerHeader.GetValue(Canvas.TopProperty) + _explorerHeader.ActualHeight));
};
behaviorCollection.Add(mouseDragBehavior);
ОБНОВЛЕНИЕ:
Вот шаблон элемента управления элемента управления:
<Style x:Key="ApplicationExplorerDefaultStyle" TargetType="Controls:ApplicationExplorer">
<Setter Property="Width" Value="150" />
<Setter Property="Height" Value="300" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="Background" Value="{StaticResource LightBlue}" />
<Setter Property="HeaderBackgroundBrush" Value="{StaticResource VeryLightBlue}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="TreeItemTemplate" Value="{StaticResource ChildTemplate}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Controls:ApplicationExplorer">
<Border BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderBrush}"
BorderThickness="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness}"
CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CornerRadius}"
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Width}"
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height}" >
<Grid x:Name="Root" MinWidth="100">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="ExplorerHeader" Grid.Row="0" Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=HeaderBackgroundBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Text="{TemplateBinding Title}" Style="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TitleStyle}" VerticalAlignment="Center" />
<Controls:LayoutToggleButton Grid.Column="2" x:Name="LayoutButton" Cursor="Hand" />
</Grid>
<Border x:Name="ExplorerBody" Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}"
Grid.Row="1" HorizontalAlignment="Stretch" BorderThickness="0" >
<toolkit:TreeViewDragDropTarget AllowedSourceEffects="Copy" x:Name="treeViewDropTarget"
HorizontalAlignment="Left" VerticalAlignment="Top" >
<sdk:TreeView x:Name="treeView" ItemsSource="{TemplateBinding Nodes}" Background="Transparent" BorderThickness="0"
ItemTemplate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeItemTemplate}"
HorizontalAlignment="Left" Margin="10 0 0 0" />
</toolkit:TreeViewDragDropTarget>
</Border>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Есть предложения?