Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF如何剪切stackpanel内容?_C#_Wpf_Mvvm_Stackpanel - Fatal编程技术网

C# WPF如何剪切stackpanel内容?

C# WPF如何剪切stackpanel内容?,c#,wpf,mvvm,stackpanel,C#,Wpf,Mvvm,Stackpanel,我需要打印一些信息,我有打印预览页,其中包含: <Grid Name="pageGrid" Width="Auto" Height="Auto" Margin="70"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="

我需要打印一些信息,我有打印预览页,其中包含:

<Grid Name="pageGrid" Width="Auto" Height="Auto" Margin="70">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Grid Grid.Column="0" Grid.Row="0" Name="headerGrid" Margin="0,0,0,5" />
    <Grid Grid.Column="0" Grid.Row="1" Name="pageSummaryGrid" Margin="0" />
    <Grid Grid.Column="0" Grid.Row="2" Name="dataGrid" Margin="0" />
    <Grid Grid.Column="0" Grid.Row="3" Name="footerGrid" Margin="0,5,0,0" VerticalAlignment="Bottom" />
</Grid>
页面是StackPanel的列表(表示打印详细信息,例如某些图片、列表等)。当某些页面[i]大于实际页面高度时,页脚变为不可见,打印详细信息(列表、图片等)被剪切(页脚被推送)


我希望页脚始终可见,如果需要剪切,只需打印详细信息。我试图设置StackPanel的MaxHeight、Height、ActualHeight和ClipToBounds属性,但没有任何效果。有什么想法吗?

您是否尝试将堆栈面板放在滚动查看器中?滚动查看器不是选项,因为这是打印预览。为什么不设置dataGrid、pageSummaryGrid的最大高度,然后查看是否显示页脚。将Auto更改为*然后使用两者的Visibility属性使它们根据需要可见或合并MaxHeight是个好主意,我解决了这个类似的问题-设置页面[I]。MaxHeightSecond代码示例,我在这里设置的代码示例包含一些附加代码(myPage.Measure(…)、myPage.UpdateLayout()等)和设置页面[I].MaxHeight在此方法调用之后不起作用(我设置了之后,因为在此方法执行之后高度和宽度属性可用)。当然,我试图“更新”我的页面,这个网格包含了那个些面板,但并没有起作用。
pageCount = pages.Count;

for (int i = 0; i < pageCount; i++)
{
    myPage = new PrintPreviewPage();
    header = new PrintPageHeader();
    footer = new PrintPageFooter();

    CreateHeaderAndFooter(i + 1, pageCount, header, footer);
    myPage.SetHeader(header);
    myPage.SetTableData(pages[i]);
    myPage.SetFooter(footer);

    pageList.Add(myPage);
}
public void SetTableData(Panel panel)
{
    dataGridGrid.Children.Add(panel);
}

public void SetHeader(FrameworkElement header)
{
    headerGrid.Children.Add(header);
}

public void SetFooter(FrameworkElement footer)
{
    footerGrid.Children.Add(footer);
}