# 問題
UWPアプリでdll読み込みを行いたいのですが、
参考となりそうなドキュメントが見つけられません。
# やりたいこと
dllとして作成したアプリのBlankPage1.xamlというページを、表示用のアプリを起動したら表示するようにしたいです。
BlankPage1.xamlはボタンを一つ配置してアラートを出すだけのテストページになっています。
表示用のアプリではソリューションエクスプローラーでdllを参照するところまでできました。
BlankPage1.xaml
xaml
1<Page 2 x:Class="dlluwptest.BlankPage1" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="using:dlluwptest" 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 Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 10 11 <Grid> 12 <Button Content="Button" Margin="60,52,0,0" VerticalAlignment="Top" Height="275" Width="290" Click="Button_Click"/> 13 14 </Grid> 15</Page>
BlankPage1.xaml.cs
cs
1namespace dlluwptest 2{ 3 /// <summary> 4 /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。 5 /// </summary> 6 public sealed partial class BlankPage1 : Page 7 { 8 public BlankPage1() 9 { 10 this.InitializeComponent(); 11 } 12 13 private async void Button_Click(object sender, RoutedEventArgs e) 14 { 15 MessageDialog md = new MessageDialog("test"); 16 await md.ShowAsync(); 17 } 18 } 19}
C#やUWPを触り始めたばかりで初歩的な質問かもしれませんが、教えていただけたらありがたいです。
よろしくお願いします。
# 追記
表示用アプリのコード
現状、方法がわからず手を付けれていません。
cs
1namespace dlltest 2{ 3 /// <summary> 4 /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。 5 /// </summary> 6 public sealed partial class MainPage : Page 7 { 8 public MainPage() 9 { 10 this.InitializeComponent(); 11 12 } 13 } 14 15}
App.xaml.cs
cs
1namespace dlltest 2{ 3 /// <summary> 4 /// 既定の Application クラスを補完するアプリケーション固有の動作を提供します。 5 /// </summary> 6 sealed partial class App : Application 7 { 8 /// <summary> 9 ///単一アプリケーション オブジェクトを初期化します。これは、実行される作成したコードの 10 ///最初の行であるため、論理的には main() または WinMain() と等価です。 11 /// </summary> 12 public App() 13 { 14 this.InitializeComponent(); 15 this.Suspending += OnSuspending; 16 } 17 18 /// <summary> 19 /// アプリケーションがエンド ユーザーによって正常に起動されたときに呼び出されます。他のエントリ ポイントは、 20 /// アプリケーションが特定のファイルを開くために起動されたときなどに使用されます。 21 /// </summary> 22 /// <param name="e">起動の要求とプロセスの詳細を表示します。</param> 23 protected override void OnLaunched(LaunchActivatedEventArgs e) 24 { 25 Frame rootFrame = Window.Current.Content as Frame; 26 27 // ウィンドウに既にコンテンツが表示されている場合は、アプリケーションの初期化を繰り返さずに、 28 // ウィンドウがアクティブであることだけを確認してください 29 if (rootFrame == null) 30 { 31 // ナビゲーション コンテキストとして動作するフレームを作成し、最初のページに移動します 32 rootFrame = new Frame(); 33 34 rootFrame.NavigationFailed += OnNavigationFailed; 35 36 if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 37 { 38 //TODO: 以前中断したアプリケーションから状態を読み込みます 39 } 40 41 // フレームを現在のウィンドウに配置します 42 Window.Current.Content = rootFrame; 43 } 44 45 if (e.PrelaunchActivated == false) 46 { 47 if (rootFrame.Content == null) 48 { 49 // ナビゲーションの履歴スタックが復元されていない場合、最初のページに移動します。 50 // このとき、必要な情報をナビゲーション パラメーターとして渡して、新しいページを 51 // 作成します 52 rootFrame.Navigate(typeof(MainPage), e.Arguments); 53 } 54 // 現在のウィンドウがアクティブであることを確認します 55 Window.Current.Activate(); 56 } 57 } 58 59 /// <summary> 60 /// 特定のページへの移動が失敗したときに呼び出されます 61 /// </summary> 62 /// <param name="sender">移動に失敗したフレーム</param> 63 /// <param name="e">ナビゲーション エラーの詳細</param> 64 void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 65 { 66 throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 67 } 68 69 /// <summary> 70 /// アプリケーションの実行が中断されたときに呼び出されます。 71 /// アプリケーションが終了されるか、メモリの内容がそのままで再開されるかに 72 /// かかわらず、アプリケーションの状態が保存されます。 73 /// </summary> 74 /// <param name="sender">中断要求の送信元。</param> 75 /// <param name="e">中断要求の詳細。</param> 76 private void OnSuspending(object sender, SuspendingEventArgs e) 77 { 78 var deferral = e.SuspendingOperation.GetDeferral(); 79 //TODO: アプリケーションの状態を保存してバックグラウンドの動作があれば停止します 80 deferral.Complete(); 81 } 82 } 83}
回答2件
あなたの回答
tips
プレビュー