文章出處

DeviceFamily Veiws 可以為特定的設備(Mobile、Desktop等)制作特定的XAML視圖,這種方式可以完全定制XMAL和共享后臺代碼。

  以 Mobile 和 Desktop 為例:

  • 新建兩個文件夾 DeviceFamily-Miobile 和 DeviceFamily-Desktop ;

                     

 

  • 然后在兩個文件夾中都添加一個 MainPage.xaml ;

                 

  • 如果在 Mobile 設備上運行應用程序,它將從DeviceFamily-Mobile/MainPage.xaml 加載 XMAL; 如果在 Desktop 設備上運行應用程序,它將從DeviceFamily-Desktop/MainPage.xaml 加載 XMAL; 對于其他設備將加載主文件夾下的 MainPage.xaml;

 

  • Example
  • DeviceFamily-Mobile/MainPage.xaml
 1 Page
 2     x:Class="_DeviceFamily.DeviceFamily_Mobile.MainPage"
 3     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 4     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 5     xmlns:local="using:_DeviceFamily.DeviceFamily_Mobile"
 6     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 7     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 8     mc:Ignorable="d">
 9 
10     <Grid Background="Blue">
11         <TextBlock Text="Hello DeviceFamily-Mobile" VerticalAlignment="Center" FontSize="24" />
12     </Grid>
13 </Page>
  • Mobile 上的運行效果

                         

 

  • DeviceFamily-Desktop/MainPage.xaml
 1 <Page
 2     x:Class="_DeviceFamily.DeviceFamily_Desktop.MainPage"
 3     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 4     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 5     xmlns:local="using:_DeviceFamily.DeviceFamily_Desktop"
 6     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 7     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 8     mc:Ignorable="d">
 9 
10     <Grid Background="Red">
11         <TextBlock VerticalAlignment="Center" Text="Hello DeviceFamily-Desktop" FontSize="56" />
12     </Grid>
13 </Page>
  • Desktop 上的運行效果

                     

 

  • 主文件下的 MainPage.xaml
<Page
    x:Class="_DeviceFamily.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:_DeviceFamily"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Yellow">
        <TextBlock VerticalAlignment="Center" Text="Hello DeviceFamily-Desktop" FontSize="48" />
    </Grid>
</Page>
  •  運行效果(由于沒有 Table  之類的第三種設備,所以此運行效果省略 gg)

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()