uwp使用资源限定符Devicefamily不同设备使用不同布局

步骤:

1. 删除MainPage.xaml
2. App下新建两个文件夹:devicefamily-desktop,devicefamily-mobile
3. App下新建MyPage.cs类
4. 两个文件夹内新建MyPage.xaml文件,注意指向的类和命名空间为MyPage.cs类和它的命名空间
5. 生成项目
6. 初始化组件

初始化组件:MyPage.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;

namespace App1
{
    public partial class MyPage : Page
    {
        public MyPage()
        {
            this.InitializeComponent(); // app生成后自动产生
        }
    }
}

两个文件下的MyPage.xaml

devicefamily-desktop:
<Page
    x:Class="App1.MyPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <TextBlock Text="桌面" FontSize="60" HorizontalAlignment="Center"/>
    </Grid>
</Page>

 

posted @ 2018-05-21 00:39  maoriaty  阅读(156)  评论(0编辑  收藏  举报