这可能看起来像一个愚蠢的问题,但请多多包涵,因为我对 WPF 很陌生,遗憾的是 UI 不是我的主要技能领域,所以我很难理解 WPF 的概念。
我有一个用户控件,其中包含一个停靠面板,然后包含一个树视图,树视图使用分层数据模板绑定,效果很好,所有项目和子控件都被绑定,我对粗糙感到满意布局结果。但是我想在最后一个绑定的树视图项下添加一个按钮。
基本上这就是我想要实现的目标:
目前我在停靠面板中有一个网格,它有两行,一排用于树视图,另一排用于按钮,但显然该按钮不是树视图的一部分,我希望它位于树的滚动区域内视图,因此它作为它的一部分出现,并且只出现在最后一个项目之后。
这是我当前的 XAML:
<DockPanel>
<Grid Width="Auto" Height="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="23"/>
</Grid.RowDefinitions>
<TreeView ItemsSource="{Binding Path=Steps}" FontFamily="Calibri" FontSize="14" DataContext="{Binding}" Grid.Row="0">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="Margin" Value="20,20,0,0"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:StepViewModel}" ItemsSource="{Binding Segments}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type local:SegmentViewModel}">
<DockPanel HorizontalAlignment="Stretch" >
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<myUserControl:SegmentLayout HorizontalAlignment="Stretch"/>
<TextBlock Text="{Binding Value}"/>
</StackPanel>
</DockPanel>
</DataTemplate>
</TreeView.Resources>
</TreeView>
<Button HorizontalAlignment="Left" Content="Add Step" Name="addStepButton" Height="23" Width="103" Grid.Row="1"/>
</Grid>
哦,在你问之前,是的,我基本上是在翻录 SharePoint 工作流设计器,这是一个内部工具,出于某种原因,我需要编写一个完成的轻量级工作流引擎,并在 WPF 中为其设计一个看起来非常相似的设计器到 SP 一。我不做商业决策,只是一个代码猴子;)。
非常感谢
保罗