我花了一天的大部分时间试图弄清楚这一点,我知道问题是 TextBlock 认为它具有无限宽度,所以包装永远不会发生,我尝试了很多绑定来设置网格的宽度,内容窗格等;没有任何运气;这个用户控件托管在一个更大的应用程序的 ig:Dock 中,可以动态调整大小,所以我不能只为文本设置宽度,我相信我需要某种绑定......任何帮助都是赞赏。
<UserControl x:Class="VistaSTAR_Client.Views.XMLEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:igDock="http://infragistics.com/DockManager"
xmlns:ig="http://schemas.infragistics.com/xaml"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<UserControl.Resources>
<SolidColorBrush x:Key="xmlValueBrush" Color="Blue" />
<SolidColorBrush x:Key="xmAttributeBrush" Color="Red" />
<SolidColorBrush x:Key="xmlTagBrush" Color="DarkMagenta" />
<SolidColorBrush x:Key="xmlMarkBrush" Color="Blue" />
<DataTemplate x:Key="attributeTemplate">
<StackPanel Orientation="Horizontal" Margin="3,0,0,0" HorizontalAlignment="Center">
<TextBlock Text="{Binding Path=Name}" Foreground="{StaticResource xmAttributeBrush}"/>
<TextBlock Text="="" Foreground="{StaticResource xmlMarkBrush}"/>
<TextBlock Text="{Binding Path=Value}" Foreground="{StaticResource xmlValueBrush}"/>
<TextBlock Text=""" Foreground="{StaticResource xmlMarkBrush}"/>
</StackPanel>
</DataTemplate>
<HierarchicalDataTemplate x:Key="NodeTemplate">
<StackPanel Orientation="Horizontal" Focusable="False">
<TextBlock x:Name="tbName" Text="?" />
<ItemsControl ItemTemplate="{StaticResource attributeTemplate}" ItemsSource="{Binding Path=Attributes}" HorizontalAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
<HierarchicalDataTemplate.ItemsSource>
<Binding XPath="child::node()" />
</HierarchicalDataTemplate.ItemsSource>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
<Setter TargetName="tbName" Property="Text" Value="{Binding Path=Value}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="tbName" Property="Text" Value="{Binding Path=Name}"/>
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
<XmlDataProvider x:Key="xmlDataProvider">
</XmlDataProvider>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<igDock:XamDockManager Name="XMLDockManager" Theme="IGTheme" LayoutMode="FillContainer">
<igDock:XamDockManager.Panes>
<igDock:SplitPane Width="Auto" HorizontalAlignment="Stretch">
<igDock:TabGroupPane Width="Auto" HorizontalAlignment="Stretch">
<igDock:ContentPane Name="XMLTreeView" Header="Tree View" Width="Auto" HorizontalAlignment="Stretch">
<TreeView Name="treeView1" Background="AliceBlue" HorizontalAlignment="Stretch" Height="Auto" Width="Auto" Margin="5,5,5,5"
ItemsSource="{Binding Source={StaticResource xmlDataProvider}, XPath=*}" ItemTemplate= "{StaticResource NodeTemplate}"/>
</igDock:ContentPane>
<igDock:ContentPane Name="XML" Header="Editor">
<TextBox HorizontalAlignment="Stretch" Name="text" Text=" " TextWrapping="WrapWithOverflow" Height="Auto" Width="Auto"
VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch" AcceptsReturn="True" AcceptsTab="True" Margin="5,5,5,5" Grid.Row="1" />
</igDock:ContentPane>
</igDock:TabGroupPane>
</igDock:SplitPane>
</igDock:XamDockManager.Panes>
</igDock:XamDockManager>
</Grid>
</UserControl>