在treeviewItem模板中网格的RenderSize越来越小

时间:2018-09-29 15:20:07

标签: wpf grid treeviewitem

我在TreeViewItem的网格中的Part_Header(ContentPresenter)的渲染大小从父网格的rendersize减小了。

Parent and Child RenderSize values

下面是TreviewItem模板的代码。我有一个文本块,需要显示为父网格宽度的整个长度。 Textblock从通过其父级计算的父网格宽度获取宽度

<HierarchicalDataTemplate x:Key="DocTemplate" ItemsSource="{Binding Pages}">

    <Grid x:Name="m_Grid" Background="Aqua" MaxWidth="{Binding  RelativeSource={RelativeSource  Mode=FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=3}, 
            Path=ActualWidth, UpdateSourceTrigger=PropertyChanged}" RenderSize="300,52">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="4" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.ToolTip>
            <ToolTip>
                <StackPanel Orientation="Horizontal">
                    <Image
                        Width="{local:ApplicationBinder AButtonSize}"
                        Height="{local:ApplicationBinder AButtonSize}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Source="{DynamicResource PDFDoc}"
                        Stretch="UniformToFill" />
                    <Grid Width="4" />
                    <TextBlock
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"
                        Style="{DynamicResource Heading2}"
                        Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"
                        TextTrimming="WordEllipsis" />
                </StackPanel>
            </ToolTip>
        </Grid.ToolTip>
        <Image
            Grid.Column="1"
            Width="{local:ApplicationBinder Path=AButtonSize}"
            Height="{local:ApplicationBinder Path=AButtonSize}"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Source="{DynamicResource PDFDoc}"
            Stretch="UniformToFill" />
        <!--  options Button  -->
        <mui:ModernButton
            Grid.Column="2"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Command="{Binding AddNewPageCommand}"
            CommandParameter="{Binding}"
            EllipseDiameter="{local:ApplicationBinder Path=AButtonSize}"
            EllipseStrokeThickness="1"
            IconHeight="{local:ApplicationBinder Path=AButtonSize}"
            IconWidth="{local:ApplicationBinder Path=AButtonSize}"
            IsEnabled="{Binding ParentRoute.Me.IsOriginator, UpdateSourceTrigger=PropertyChanged}"
            ToolTip="This Tool Will Allow You to Modify the Selected Document....">
            <mui:ModernButton.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ParentRoute.Me.IsOriginator, UpdateSourceTrigger=PropertyChanged}" Value="True">
                            <Setter Property="mui:ModernButton.Source" Value="{DynamicResource Settings}" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ParentRoute.Me.IsOriginator, UpdateSourceTrigger=PropertyChanged}" Value="False">
                            <Setter Property="mui:ModernButton.Source" Value="{DynamicResource SettingsNorm}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </mui:ModernButton.Style>
        </mui:ModernButton>
        <!--  Document Details  -->
        <!--<StackPanel
            Grid.Column="3"
            Margin="7"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Orientation="Vertical" 
            MaxWidth="{Binding ActualWidth, ElementName=m_Grid, UpdateSourceTrigger=PropertyChanged}">-->
        <Grid  Grid.Column="3"
            Margin="7">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <TextBlock
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Style="{DynamicResource Heading2}"
                Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"
                TextTrimming="WordEllipsis" />
            <Grid Height="3" />
            <TextBlock
                Grid.Row="1"
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Style="{DynamicResource NormalText}"
                Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}"
                TextTrimming="WordEllipsis" />
        <!--</StackPanel>-->
        </Grid>
    </Grid>
</HierarchicalDataTemplate>

如何使子网格值的渲染大小与父网格值相同?

0 个答案:

没有答案