我希望在每個節點的循環中能夠在節點訪問時以及在其離開將背景設置爲透明時再改變背景。在樹狀視圖中嵌套節點的wpf訪問堆棧面板
我的問題:我不知道如何訪問堆棧面板從後面的代碼更改BackGround。 我希望得到任何幫助
這裏是我的代碼: TreeView控件
<TreeView Grid.Column="1" Grid.Row="0" ItemsSource="{Binding ListOfNodes}"
Background="Linen" Margin="0,0,0,-0">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate x:Name="HDT_node" DataType="Node" ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal"
MouseLeftButtonDown="btnTreeItemStartPlay"
Background="Transparent">
<Image Source="{Binding Path=image.Source}" Width="30" Height="30"
HorizontalAlignment="Left"
MouseEnter="ZoomStart" MouseLeave="ZoomStop" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
等級節點:
public class Node
{
public Image image { get; set; }
public List<Node> Children { get; set; }
public Node()
{
}
public Node(Image imageIn, int orderIndexIn)
{
image = imageIn;
Children = new List<Node>();
}
}
與此類似:http://stackoverflow.com/questions/34117944/listbox-items-return-string-when-datatemplate-is-button –