私は、携帯電話用に追加の適応UI状態を使用するのではなく、モバイルデバイス用に別々のビューセットを作成するために取り組んでいます。私はViews
のサブフォルダにDeviceFamily-Mobile
という名前のサブフォルダを追加し、オーバーライドするのと同じ名前の新しいView
を追加することでこれを達成することができます。ViewModelをモバイルビューに追加する
携帯デバイス/エミュレータで「モバイル」を動作させて表示するには、次のようなものがあります:View
<Page x:Class="MyApp.PayeesPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:Template10.Behaviors"
xmlns:controls="using:Template10.Controls"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:MyApp.Models"
xmlns:viewModels="using:MyApp.ViewModels"
xmlns:views="using:MyApp.Views"
mc:Ignorable="d">
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="MobileTextBlock"
Foreground="{ThemeResource ForegroundColorBrush}"
Text="MOBILE" />
</RelativePanel>
</Page>
私は実際の表示にそのような便利なもの、私を許可するようにDataContext
を設定しようとする場合は、:
<Page.DataContext>
<viewModels:PayeesPageViewModel x:Name="ViewModel" />
</Page.DataContext>
をPayeesPage
に移動するときに、私はエラーを取得する:
タイプ 'Windows.UI.Xaml.Controls.TextBlock'のオブジェクトをキャストして 'MyApp.ViewModels.PayeesPageViewModel'と入力できません。
これは、を元のPayeesPage
に設定したのと同じ方法です。正常に動作します。これらの代替のDataContext
を別の方法で設定する方法はありますか、何か不足していますか?
THXをあなたのソリューションを共有するために、DeviceFamily-Typeフォルダに関する多くの記事があります。たとえば、http://igrali.com/2015/08/02/three-ways-to-set-specific-devicefamily-xaml-views-in -uwp/ –
これは氷の記事 - 私は私の多くの情報を得た。私の問題は、私が見つけた情報の中には、同じ「x:Class」を共有するために必要なビューがないことが指摘されていたため、ReSharperの赤い塊がこのケースでは少し誤解を招いていました。 –