我正在尝试为 Windows 10 开发一个应用程序。但是对于所有新的屏幕大小,我似乎无法弄清楚如何让一个元素适合设备屏幕的当前大小。
例如,如果您调整它的大小,我希望 TextBlock 适合窗口的宽度。我已经尝试过 ViewBox、VariableSizedWrapGrid 等,但似乎没有什么能解决我的问题。有谁知道?
更新:这是我试图适应下面窗口大小的搜索框。如果我在其上放置背景颜色,则网格会填充整个窗口,RelativePanel 也会如此。但是 SearchBox 拒绝伸展......我不希望搜索框按比例缩放,只是它的宽度适合窗口/设备宽度。
<!-- SEARCH GRID -->
<Grid Canvas.ZIndex="5" x:Name="GridSearchPackage" HorizontalAlignment="Stretch" Visibility="Visible" Opacity="0.85" Background="White">
<RelativePanel HorizontalAlignment="Stretch" Margin="5,5,0,0" >
<Button x:Name="ButtonBackSearchGrid" Height="36" Width="36" FontSize="10" Margin="0,7,5,0"
Style="{StaticResource BackButtonStyle}"
Click="ButtonBackSearchGrid_Click"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button" BorderBrush="Black" BorderThickness="3">
<FontIcon x:Name="backButtonIcon" FontWeight="Bold" FontSize="20" Foreground="{StaticResource AppDarkBlueColor}" Glyph="" />
</Button>
<TextBlock x:Name="TextBlockPopupSearchTitle" RelativePanel.RightOf="ButtonBackSearchGrid" Foreground="{StaticResource AppDefaultBlueColor}" Text="Search XZY" FontSize="34"/>
<SearchBox FontSize="20" RelativePanel.Below="TextBlockPopupSearchTitle" HorizontalAlignment="Stretch" PlaceholderText="search" Margin="0,10,0,0" QuerySubmitted="SearchBox_QuerySubmitted" QueryText="{Binding SearchText, Mode=TwoWay}"/>
</RelativePanel>
</Grid>