【发布时间】:2015-07-07 23:37:33
【问题描述】:
下面我有一些相当原始的代码(仅供测试,试图证明这一点)。我有一个网格行和一个网格列,它们的宽度和高度分别定义为“*”,以便它们用完其他行/列未使用的所有可用空间。相当标准,至少我是这么认为的。
<Grid x:Name="PageContent" Background="{Binding PageColor}">
<Grid.RowDefinitions>
<RowDefinition Height="81" />
<RowDefinition Height="*" />
<RowDefinition Height="92" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Grid.Row="0" Grid.Column="0" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource TopBackButtonStyle}" />
<Button x:Name="searchButton" Grid.Row="0" Grid.Column="2" Click="GoSearch" Style="{StaticResource TopSearchButtonStyle}" HorizontalAlignment="Right"/>
<Button x:Name="settingsButton" Grid.Row="0" Grid.Column="3" Click="GoSettings" Style="{StaticResource TopSettingsButtonStyle}" HorizontalAlignment="Right"/>
<ScrollViewer Grid.Row="1" Grid.ColumnSpan="4" Name="MainScrollViewer" ZoomMode="Disabled" IsTabStop="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Padding="0,0,0,20" >
<Image x:Name="PDFRenderedImage" AutomationProperties.Name="placeholder image" Source="Assets/placeholder-sdk.png" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="10,10,10,10"/>
</ScrollViewer>
现在,我正在尝试使用 Microsoft 为示例定义的一些更便宜的 PDF 显示例程。其中之一是使用带有 PdfPageRenderOptions 的 RenderToStreamAsync。
我想做的一件事是尝试缩放 PDF 生成的图像,以便无论如何页面都适合屏幕。但是,至少使用 PdfPageRenderOptions 这样做意味着我需要提前知道宽度/高度。
那么,如何以编程方式获取在使用该元素之前定义为“*”的原始/列中的 UIElement 的宽度和高度(意思是,即使该大小,我如何获得可用区域大小尚未使用)。
有没有人发现更好的方法?
【问题讨论】:
标签: xaml visual-studio-2013 windows-runtime grid winrt-xaml