简体   繁体   English

Windows 8 Store App中的XAML对齐方式

[英]XAML alignment in Windows 8 Store App

Not being at all familiar with XAML, I'm trying to get a very simple layout designed where the main page consists of two parts: 我一点都不熟悉XAML,我试图设计一个非常简单的布局,主页面由两部分组成:

  1. On the left, I want an image that will scale to fit the available height but maintain its aspect ratio. 在左边,我想要一个可以缩放以适应可用高度但保持其纵横比的图像。
  2. On the right, I want a panel that will eventually contain text and controls - at the moment I just have text. 在右边,我想要一个最终将包含文本和控件的面板 - 目前我只有文本。

I can get the image to behave ok by using a ViewBox but I can't seem to get the right side of the screen to fill the remaining gap. 我可以通过使用ViewBox使图像表现良好,但我似乎无法获得屏幕的右侧来填补剩余的差距。 See screenshot: 看截图:

截图显示对齐错误

What I want is for the area that contains the text to stretch to the right with the text centred within it. 我想要的是包含文本的区域向右伸展,文本居中于其中。

The relevant XAML code is: 相关的XAML代码是:

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
  <StackPanel Orientation="Horizontal">
    <Viewbox HorizontalAlignment="Right">
      <Image Source="Assets/ABCImage.png"></Image>
    </Viewbox>
    <StackPanel Orientation="Vertical">
      <TextBlock Text="ABC Viewer"
                 TextAlignment="Center"
                 FontSize="48"></TextBlock>
      <TextBlock Text="Test application"
                 TextAlignment="Center"
                 FontSize="24"></TextBlock>
    </StackPanel>
  </StackPanel>
</Grid>

This is taking me far too long to figure out. 这让我花了很长时间才弄明白。 Can someone please put me out of my misery? 有人可以把我从痛苦中解救出来吗?

Try this : 尝试这个 :

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <Viewbox Grid.Column="0"
           HorizontalAlignment="Right">
    <Image Source="Assets/ABCImage.png"></Image>
  </Viewbox>
  <StackPanel Grid.Column="1">
    <TextBlock Text="SEM Viewer"
               TextAlignment="Center"
               FontSize="48" />
    <TextBlock Text="Test application"
               TextAlignment="Center"
               FontSize="24" />
  </StackPanel>
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows 8中的TreeView在XAML中存储应用程序 - TreeView in windows 8 store app in XAML 垂直滚动gridview XAML windows商店应用程序 - vertically scrolling gridview XAML windows store app 如何在Windows 8应用商店应用(C#/ XAML)中正确添加图像 - How to properly add image in Windows 8 store app (C#/XAML) 如何在Windows应用商店应用中本地化通知和组合框? (C#/ XAML,多语言应用工具包) - How to localize notifications and combobox in Windows store app? (C#/XAML, Multilingual App Toolkit) 是否可以将DirectX的单个全屏页面添加到XAML / C#Windows 8 Store App? - Is it possible to add single full screen page of DirectX to a XAML/C# Windows 8 Store App? 在xaml中进行转换后,StoryBoard始终以原始坐标开始(Windows Store应用程序) - StoryBoard always starts with original co-ordinates after Transform in xaml (windows store app) 如何在数据绑定对象中使用XAML HexNumbers for Windows Store App图标(Segoe UI Symbol)? - How do I use XAML HexNumbers for Windows Store App icons (Segoe UI Symbol) in databound objects? Windows 8 Store XAML / C#中的HttpPost - HttpPost in windows 8 Store XAML/C# 适用于Windows 8商店应用程序的PropertyGrid(WinRT / XAML) - PropertyGrid for Windows 8 Store Apps (WinRT/XAML) Windows应用商店设置 - windows store app setting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM