2

私はこれを理解しようとして一日のほとんどを費やしました.TextBlockが無限の幅を持っていると考えていることが問題であることを知っています. ContentPane など; 運がない。このユーザー コントロールは、動的にサイズ変更できるより大きなアプリケーションの 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="=&quot;" Foreground="{StaticResource xmlMarkBrush}"/>
                <TextBlock Text="{Binding Path=Value}" Foreground="{StaticResource xmlValueBrush}"/>
                <TextBlock Text="&quot;" 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>
4

2 に答える 2

2

Ok, here may be several things that may cause your text do not wrap.

  1. If you want a text inside a TextBox or TextBlock be wrapped you need to set TextWrapping="Wrap",
  2. You must use a WrapPanel and not a StackPanel, a Stack Panel take his width from the items it have.
  3. And this is most important, each tree view has the content inside a ScrollViewer, by default the TreeView's ScrollViewer give its items Infinity width due has the Horizantal bar enabled, you need to disable this if you want the text and items be wrapped (ScrollViewer.HorizontalScrollBarVisibility="Disabled").

Hope this could help you...

于 2012-11-09T16:22:26.360 に答える
0
<TextBlock Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ENTERTYPE}, Path=ActualWidth}"/>

の幅ENTERTYPEを制御する先祖の型はどこにありますか。TextBlock

つまり、TextBlockが 内に含まれている場合StackPanel、おそらく ENTERTYPE=StackPanel

于 2012-11-09T02:26:44.253 に答える