代码之家  ›  专栏  ›  技术社区  ›  Stephan

WPF DataGridDetailsTemplate扩展错误

  •  0
  • Stephan  · 技术社区  · 16 年前

    我使用的是wpftoolkit中的一个数据报,并且遇到了rowdetailsTemplate的问题。

    我的rowdetailTemplate包含3个项目:2个富文本框和一个按钮。我想要的是按钮保持停靠在窗口的右边缘,两个富文本框展开以填充其余的空间。我遇到的问题是,如果我将按钮停靠在窗口右侧,当我放大窗口时,按钮会正确移动并保持在外边缘,但是如果我将窗口向后收缩,它不会收缩并保持相同的间距。这会导致它位于窗口外且不可见。这是预期的行为吗?如果有人知道一个解决方法或解决方案来设置整个细节模板,如我所描述的,我会很感激一些建议。

    相关代码:

    <toolkit:DataGrid.RowDetailsTemplate>
        <DataTemplate>
    <DockPanel Width="Auto">
        <DockPanel DockPanel.Dock="Right">
            <Button Height="50" Width="75" Margin="5 5 0 5" DockPanel.Dock="Right">
                <Image Source="Resources/ArrowOutOfBox.bmp" />
            </Button>
        </DockPanel>
        <StackPanel Margin="20 0 20 0" Orientation="Horizontal" HorizontalAlignment="Left" DockPanel.Dock="Left">
            <StackPanel>
                <ToolBar>
                    <ToggleButton MinWidth="20" Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=rtbNewComment}" TextBlock.FontWeight="Bold" Content="B" />
                    <ToggleButton MinWidth="20" Command="EditingCommands.ToggleItalic" CommandTarget="{Binding ElementName=rtbNewComment}" TextBlock.FontStyle="Italic" Content="I" />
                    <ToggleButton MinWidth="20" Command="EditingCommands.ToggleUnderline" CommandTarget="{Binding ElementName=rtbNewComment}">
                        <TextBlock TextDecorations="Underline">U</TextBlock>
                    </ToggleButton>
                </ToolBar>
                <RichTextBox 
                                        x:Name="rtbNewComment"
                                        Height="100"
                                        Margin="5 5 0 5"
                                        FlowDirection="LeftToRight" 
                                        VerticalScrollBarVisibility="Auto"
                                        IsReadOnly="False" 
                                        SpellCheck.IsEnabled="true" 
                                        >
                </RichTextBox>
            </StackPanel>
            <StackPanel>
                <RichTextBox 
                                        x:Name="rtbCommentHistory"
                                        Height="125"
                                        Margin="5 5 0 5"
                                        FlowDirection="LeftToRight" 
                                        VerticalScrollBarVisibility="Auto"
                                        IsReadOnly="True" 
                                        SpellCheck.IsEnabled="true" 
                                        >
                    <RichTextBox.Resources>
                        <Style TargetType="{x:Type Paragraph}">
                            <Setter Property="Margin" Value="0" />
                        </Style>
                    </RichTextBox.Resources>
                </RichTextBox>
            </StackPanel>
        </StackPanel>
    
    </DockPanel>
    </DataTemplate>
    </toolkit:DataGrid.RowDetailsTemplate>
    
    1 回复  |  直到 16 年前
        1
  •  0
  •   Stephan    16 年前

    结果发现,在细节中,dockpanel试图使自己居中,但center is正在计算将向上而不是向下。通过设置HorizontalSignment=“Left”,它解决了问题。我仍然希望有一种方法可以使所有项目的大小与当前大小成比例以填充方框,但目前还没有运气。