c# wpf 样式化 HierarchicalDataTemplate 以表示为键值对 link
c# wpf styling HierarchicalDataTemplate to represent as key value pair link
我将 XML 表示为 WPF 中的树视图。这些节点使用 HierarchicalDataTemplate 来表示 Xml 属性及其值,如下所示。
<HierarchicalDataTemplate DataType="Field" ItemsSource="{Binding XPath=./*}">
<StackPanel Orientation="Horizontal" Margin="2" >
<Border BorderBrush="White" Background="{DynamicResource AccentColorBrush}" BorderThickness="2" CornerRadius="3" Margin="2,0,0,0">
<TextBlock Foreground="White" Margin="3" Text="Field" />
</Border>
<Border BorderBrush="White" Background="WhiteSmoke" BorderThickness="2" CornerRadius="3" Margin="2,0,0,0">
<TextBlock Margin="3" Text="{Binding XPath=@FieldName}" />
</Border>
</StackPanel>
</HierarchicalDataTemplate>
我希望将它们表示为 tag/key 值对,用某种 link/equal 等表示,如下图
如何通过 xaml 更改来实现这一点。我需要一些其他方法,而不是在这对之间引入 "link" 的图像以显示它们已链接。
您在找这样的东西吗?
如果是这样,你可以使用Separator
.
来实现
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="Black" Background="Green" BorderThickness="2"
CornerRadius="3" Margin="2,0,0,0">
<TextBlock VerticalAlignment="Center" Foreground="White" Margin="10,0,10,0" Text="Field" />
</Border>
<Border Grid.Column="2" BorderBrush="Black" Background="LightGray" BorderThickness="2"
CornerRadius="3" >
<TextBlock Margin="10,0,10,0" Text="Test1" />
</Border>
<Border Grid.Column="1" Margin="-6" Background="White" Height="5" CornerRadius="2">
<Separator Background="Black" Margin="2,0,2,0"/>
</Border>
</Grid>
我将 XML 表示为 WPF 中的树视图。这些节点使用 HierarchicalDataTemplate 来表示 Xml 属性及其值,如下所示。
<HierarchicalDataTemplate DataType="Field" ItemsSource="{Binding XPath=./*}">
<StackPanel Orientation="Horizontal" Margin="2" >
<Border BorderBrush="White" Background="{DynamicResource AccentColorBrush}" BorderThickness="2" CornerRadius="3" Margin="2,0,0,0">
<TextBlock Foreground="White" Margin="3" Text="Field" />
</Border>
<Border BorderBrush="White" Background="WhiteSmoke" BorderThickness="2" CornerRadius="3" Margin="2,0,0,0">
<TextBlock Margin="3" Text="{Binding XPath=@FieldName}" />
</Border>
</StackPanel>
</HierarchicalDataTemplate>
我希望将它们表示为 tag/key 值对,用某种 link/equal 等表示,如下图
您在找这样的东西吗?
如果是这样,你可以使用Separator
.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="Black" Background="Green" BorderThickness="2"
CornerRadius="3" Margin="2,0,0,0">
<TextBlock VerticalAlignment="Center" Foreground="White" Margin="10,0,10,0" Text="Field" />
</Border>
<Border Grid.Column="2" BorderBrush="Black" Background="LightGray" BorderThickness="2"
CornerRadius="3" >
<TextBlock Margin="10,0,10,0" Text="Test1" />
</Border>
<Border Grid.Column="1" Margin="-6" Background="White" Height="5" CornerRadius="2">
<Separator Background="Black" Margin="2,0,2,0"/>
</Border>
</Grid>