xaml – 如何在Windows Phone 8中制作自适应UI?

前端之家收集整理的这篇文章主要介绍了xaml – 如何在Windows Phone 8中制作自适应UI?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想制作一个视图,在小屏幕中视图变得越来越少,而且它应该很大.例如,在下面给出的480×800电话视图中的图像应该到达支持部分(其余部分可滚动),而在wxga中它应该覆盖人力资源部分.
xaml代码
  1. <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0">
  2. <StackPanel>
  3. <TextBlock Text="Contact" FontSize="30" HorizontalAlignment="Center" Foreground="Black"></TextBlock>
  4. <ScrollViewer x:Name="scroll" Height="650">
  5. <StackPanel x:Name="stack">
  6. <Border Background="#E66729" Padding="5">
  7. <TextBlock Text="Email" HorizontalAlignment="Center" FontSize="25"></TextBlock>
  8. </Border>
  9. <HyperlinkButton Margin="0,10,0" Content="xxxxxxxx" Foreground="Blue"></HyperlinkButton>
  10. <Border Margin="0,0" Background="#E66729" Padding="5">
  11. <TextBlock Text="Skype ID" HorizontalAlignment="Center" FontSize="25"></TextBlock>
  12. </Border>
  13. <TextBlock Text="xxxxxxxx" Foreground="Black" HorizontalAlignment="Center" FontWeight="SemiBold" FontSize="22"></TextBlock>
  14. <Border Margin="0,0" Background="#E66729" Padding="5">
  15. <TextBlock Text="Numbers" HorizontalAlignment="Center" FontSize="25"></TextBlock>
  16. </Border>
  17. <StackPanel>
  18. <StackPanel Orientation="Horizontal" Margin="0,5,0" HorizontalAlignment="Center">
  19. <TextBlock Text="Sales:" Foreground="Black" FontSize="22" ></TextBlock>
  20. <HyperlinkButton Content="+91-xxxxxx" Foreground="Blue"></HyperlinkButton>
  21. </StackPanel>
  22. <StackPanel Orientation="Horizontal" Margin="0,0" HorizontalAlignment="Center">
  23. <TextBlock Text="Care:" Foreground="Black" FontSize="22" ></TextBlock>
  24. <HyperlinkButton Content="+91-xxxxxxxx" Foreground="Blue"></HyperlinkButton>
  25. </StackPanel>
  26. <StackPanel Orientation="Horizontal" Margin="0,0" HorizontalAlignment="Center">
  27. <TextBlock Text="HR:" Foreground="Black" FontSize="22" ></TextBlock>
  28. <HyperlinkButton Content="+91-xxxxxxxxxx" Foreground="Blue"></HyperlinkButton>
  29. </StackPanel>
  30. </StackPanel>
  31. <Border Margin="0,0" Background="#E66729" Padding="5">
  32. <TextBlock Text="Support" HorizontalAlignment="Center" FontSize="25"></TextBlock>
  33. </Border>
  34. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  35. <TextBlock Text="Care:" Foreground="Black" FontSize="22" ></TextBlock>
  36. <HyperlinkButton Content="xxxxxxx" Margin="0,0" Foreground="Blue"></HyperlinkButton>
  37. </StackPanel>
  38. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  39. <TextBlock Text="Email:" Foreground="Black" FontSize="22" ></TextBlock>
  40. <HyperlinkButton Content="xxxxxxxxxxxx" Margin="0,0" Foreground="Blue"></HyperlinkButton>
  41. </StackPanel>
  42. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  43. <TextBlock Text="Skype ID:" Margin="0,0" Foreground="Black" FontSize="22" ></TextBlock>
  44. <TextBlock Text="xxxxxxxx" FontSize="22" Foreground="Black"></TextBlock>
  45. </StackPanel>
  46. <Border Margin="0,0" Background="#E66729" Padding="5">
  47. <TextBlock Text="Human Resource" HorizontalAlignment="Center" FontSize="25"></TextBlock>
  48. </Border>
  49. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  50. <TextBlock Text="Hr:" Foreground="Black" FontSize="22" ></TextBlock>
  51. <HyperlinkButton Content="xxxxxx" Foreground="Blue"></HyperlinkButton>
  52. </StackPanel>
  53. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  54. <TextBlock Text="Email:" Foreground="Black" FontSize="22" ></TextBlock>
  55. <HyperlinkButton Content="xxxxxxxx" Foreground="Blue"></HyperlinkButton>
  56. </StackPanel>
  57. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  58. <TextBlock Text="Skype ID:" Foreground="Black" FontSize="22" ></TextBlock>
  59. <TextBlock Text="orangemantra" Foreground="Black"></TextBlock>
  60. </StackPanel>
  61. </StackPanel>
  62. </ScrollViewer>
  63. </StackPanel>
  64. </Grid>

请打开图像,因为我没有声誉.
http://i.stack.imgur.com/lLQR7.png

对于自适应布局,请确保仔细使用边距.并且每个元件或容器基于其水平和垂直对齐放置.在任何时候,如果无法使用对齐放置元素,请使用网格行和列定义来更好地放置元素.使用边距将元素放置在距行或列定义的精确距离处.尽量不要使用边距,因为它们是硬编码的,在运行时它们不会改变.在行和列定义中,使用*作为因子或划分网格(如代码中所示),因为*会考虑屏幕布局大小,并在这种情况下将网格大小乘以因子12.此外,如果您不想设置列的宽度或行的高度,则可以使用Auto而不是*,并且在运行时,将分配列自动编辑代码并使其适用于所有screentype.使用scrollviewer时,请确保避免给它一个高度(如代码中所示).我添加了一个网格行,并使滚动查看器完全伸展屏幕.这是修改后的代码
  1. <Grid x:Name="ContactGrid" Margin="0,0">
  2. <Grid.RowDefinitions>
  3. <RowDefinition Height="*"/>
  4. <RowDefinition Height="12*"/>
  5. </Grid.RowDefinitions>
  6.  
  7. <TextBlock Text="Contact" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="Black"/>
  8. <ScrollViewer x:Name="scroll" IsEnabled="True" Grid.Row="1">
  9. <Grid x:Name="ContentGrid">
  10. <StackPanel x:Name="stack">
  11. <Border Background="#E66729" Padding="5">
  12. <TextBlock Text="Email" HorizontalAlignment="Center" FontSize="25"/>
  13. </Border>
  14. <HyperlinkButton Margin="0,0" Content="xxxxxxxx" Foreground="Blue"/>
  15. <Border Margin="0,0" Background="#E66729" Padding="5">
  16. <TextBlock Text="Skype ID" HorizontalAlignment="Center" FontSize="25"/>
  17. </Border>
  18. <TextBlock Text="xxxxxxxx" Foreground="Black" HorizontalAlignment="Center" FontWeight="SemiBold" FontSize="22"/>
  19. <Border Margin="0,0" Background="#E66729" Padding="5">
  20. <TextBlock Text="Numbers" HorizontalAlignment="Center" FontSize="25"/>
  21. </Border>
  22. <StackPanel>
  23. <StackPanel Orientation="Horizontal" Margin="0,0" HorizontalAlignment="Center">
  24. <TextBlock Text="Sales:" Foreground="Black" FontSize="22" />
  25. <HyperlinkButton Content="+91-xxxxxx" Foreground="Blue"/>
  26. </StackPanel>
  27. <StackPanel Orientation="Horizontal" Margin="0,0" HorizontalAlignment="Center">
  28. <TextBlock Text="Care:" Foreground="Black" FontSize="22" />
  29. <HyperlinkButton Content="+91-xxxxxxxx" Foreground="Blue"/>
  30. </StackPanel>
  31. <StackPanel Orientation="Horizontal" Margin="0,0" HorizontalAlignment="Center">
  32. <TextBlock Text="HR:" Foreground="Black" FontSize="22" />
  33. <HyperlinkButton Content="+91-xxxxxxxxxx" Foreground="Blue"/>
  34. </StackPanel>
  35. </StackPanel>
  36. <Border Margin="0,0" Background="#E66729" Padding="5">
  37. <TextBlock Text="Support" HorizontalAlignment="Center" FontSize="25"/>
  38. </Border>
  39. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  40. <TextBlock Text="Care:" Foreground="Black" FontSize="22" ></TextBlock>
  41. <HyperlinkButton Content="xxxxxxx" Margin="0,0" Foreground="Blue"/>
  42. </StackPanel>
  43. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  44. <TextBlock Text="Email:" Foreground="Black" FontSize="22" />
  45. <HyperlinkButton Content="xxxxxxxxxxxx" Margin="0,0" Foreground="Blue"/>
  46. </StackPanel>
  47. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  48. <TextBlock Text="Skype ID:" Margin="0,0" Foreground="Black" FontSize="22" />
  49. <TextBlock Text="xxxxxxxx" FontSize="22" Foreground="Black"></TextBlock>
  50. </StackPanel>
  51. <Border Margin="0,0" Background="#E66729" Padding="5">
  52. <TextBlock Text="Human Resource" HorizontalAlignment="Center" FontSize="25"/>
  53. </Border>
  54. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  55. <TextBlock Text="Hr:" Foreground="Black" FontSize="22" />
  56. <HyperlinkButton Content="xxxxxx" Foreground="Blue"/>
  57. </StackPanel>
  58. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  59. <TextBlock Text="Email:" Foreground="Black" FontSize="22" />
  60. <HyperlinkButton Content="xxxxxxxx" Foreground="Blue"/>
  61. </StackPanel>
  62. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  63. <TextBlock Text="Skype ID:" Foreground="Black" FontSize="22" />
  64. <TextBlock Text="orangemantra" Foreground="Black"/>
  65. </StackPanel>
  66. </StackPanel>
  67. </Grid>
  68. </ScrollViewer>
  69. </Grid>

您还可以使用Pivot控件来组织支持内容.这样,用户可以轻扫您需要提供的信息.如果有任何问题,请在评论部分告诉我

猜你在找的Windows相关文章