dockpanel内的xaml按钮消失

时间:2018-05-30 17:26:57

标签: wpf xaml scrollviewer dockpanel

我有一个数据网格,在dockpanel内有3个按钮。当数据网格列表填满页面时,会出现垂直滚动,3个按钮消失。即使你一直滚动到底部,按钮也不存在。

<HeaderedContentControl>
    <HeaderedContentControl.Header>
        <TextBlock TextWrapping="Wrap">
            <TextBlock.Text>
                <MultiBinding StringFormat="Associated WUCs for {0} ({1})">
                    <Binding Path="Class.Name" />
                    <Binding Path="Class.Narrative" />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </HeaderedContentControl.Header>
    <DockPanel>
        <DockPanel>
        <m:DataGrid ItemsSource="{Binding Source={StaticResource ViewSource}}"
                    DockPanel.Dock="Top"
                    Style="{StaticResource {x:Type DataGrid}}"
                    CanUserAddRows="False"
                    CanUserDeleteRows="True">
            <DataGrid.Columns>
                <DataGridTemplateColumn IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Style="{StaticResource DataGridButtonStyle}"
                                    Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext.DeleteCommand}"
                                    CommandParameter="{Binding}">
                                <Image Style="{StaticResource DataGridButtonImageStyle}"
                                       Source="{StaticResource DeleteImage}" />
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Header="{Binding Source={x:Type entities:OtherClass}, ConverterParameter='Name', Converter={StaticResource DisplayNameConverter}}"
                                    Binding="{Binding Name}"
                                    IsReadOnly="True"
                                    SortDirection="Ascending" />
                <DataGridTextColumn Header="{Binding Source={x:Type entities:OtherClass}, ConverterParameter='Narrative', Converter={StaticResource DisplayNameConverter}}"
                                    Binding="{Binding Narrative}"
                                    IsReadOnly="True"
                                    SortDirection="Ascending" />
            </DataGrid.Columns>
            </m:DataGrid>
        </DockPanel>
        <Button Command="{Binding AddCommand}">
            <StackPanel Orientation="Horizontal">
                <Image Source="{StaticResource AddImage}"
                       Height="16" />
                <TextBlock Text=" Add" />
            </StackPanel>
        </Button>
        <Button Command="{Binding OkCommand}"
                DockPanel.Dock="Right"
                Content="OK" />
        <Button Command="{Binding CancelCommand}"
                DockPanel.Dock="Right"
                Content="Cancel"
                HorizontalAlignment="Right" />
    </DockPanel>
</HeaderedContentControl>

当滚动出现时,我希望3个按钮转到滚动条的底部和外部。我尝试过使用stackpanel,但禁用了滚动条。我还尝试将datagrid包装在一个dockpanel中,并将3个按钮包含在另一个dockpanel中,但它们似乎不共享页面并仅显示datagrid的列表。

1 个答案:

答案 0 :(得分:0)

我做的一种方法是将3个按钮包裹在另一个停靠栏内并将其停靠在底部。我把那个dockpanel移到datagrid上面(非常重要)。

我解决这个问题的另一种方法是将dockpanel更改为网格并为其提供2行,1为数据网格,另一行为3个按钮(包围堆栈面板)。