這可能會看起來像一個愚蠢的問題,但請忍受我,因爲我是WPF的新手,UI可悲不是我的主要技能領域,所以我努力得到我的頭腦圍繞着WPF的概念。WPF將按鈕添加到Treeview的底部
我有一個用戶控件,其中包含一個停靠面板,然後包含一個樹視圖,樹視圖綁定使用分層數據模板,這是偉大的,所有的項目和子控件綁定,我對粗糙的佈局結果感到滿意。但是我想在最後綁定的樹視圖項下添加一個按鈕。
基本上這就是我想acheive:
目前我有有兩行,一個樹視圖和一個按鈕,但顯然該按鈕是固定面板內網格不是樹視圖的一部分,我希望它在樹視圖的滾動區域內,因此它作爲它的一部分出現,並且只出現在最終項目之後。
這是我目前的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非常相似。我不做商業決策,只是一個代碼猴子;)。
非常感謝
保羅
您好,感謝的是,我已經做了如你所說,我的樹視圖仍然呈現正常,但包含按鈕樹型視圖項目不會出現。有任何想法嗎?謝謝 – 2011-05-06 09:35:19
不用擔心,我知道了,我忘了將TreeView上的ItemsSource更改爲CompositeCollection。現在工作,很好的解決方案和快速反應,非常感謝:) – 2011-05-06 09:42:22
很高興爲你工作:) – 2011-05-06 09:48:20