{"id":497,"date":"2019-11-05T17:28:38","date_gmt":"2019-11-05T08:28:38","guid":{"rendered":"http:\/\/marius.main.jp\/software\/blog\/?p=497"},"modified":"2020-06-07T17:31:34","modified_gmt":"2020-06-07T08:31:34","slug":"post-497","status":"publish","type":"post","link":"https:\/\/todosoft.net\/blog\/?p=497","title":{"rendered":"MahAppsDialog\u306e\u8868\u793a"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">MainView.xaml<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">&lt;Controls:MetroWindow \n        x:Class=\"WpfApp12.View.MainView\"\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n        xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\"\n        xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\"\n        xmlns:local=\"clr-namespace:WpfApp12.View\"\n        mc:Ignorable=\"d\"\n        \n        xmlns:Controls=\"clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro\"\n        xmlns:ei=\"http:\/\/schemas.microsoft.com\/xaml\/behaviors\"\n        xmlns:i=\"http:\/\/schemas.microsoft.com\/xaml\/behaviors\"\n        xmlns:l=\"http:\/\/schemas.livet-mvvm.net\/2011\/wpf\"\n        xmlns:vm=\"clr-namespace:WpfApp12.ViewModel\"\n        \n        xmlns:Dialog=\"clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro\"\n        Dialog:DialogParticipation.Register=\"{Binding}\"\n        \n        TextElement.Foreground=\"{DynamicResource MaterialDesignBody}\"\n        TextElement.FontWeight=\"Regular\"\n        TextElement.FontSize=\"13\"\n        TextOptions.TextFormattingMode=\"Ideal\" \n        TextOptions.TextRenderingMode=\"Auto\"        \n        Background=\"{DynamicResource MaterialDesignPaper}\"\n        FontFamily=\"{DynamicResource MaterialDesignFont}\"\n        ResizeMode=\"CanResizeWithGrip\"\n        WindowStartupLocation=\"CenterScreen\"\n        GlowBrush=\"{DynamicResource AccentColorBrush}\"\n        WindowTransitionsEnabled=\"False\"\n        TitleCharacterCasing=\"Normal\"\n        ShowIconOnTitleBar=\"True\"\n        \n        Title=\"MainView\" Height=\"450\" Width=\"800\">\n\n    &lt;Window.DataContext>\n        &lt;vm:MainViewModel>\n            &lt;vm:MainViewModel.MahAppsDialogCoordinator>\n                &lt;Dialog:DialogCoordinator\/>\n            &lt;\/vm:MainViewModel.MahAppsDialogCoordinator>\n        &lt;\/vm:MainViewModel>\n    &lt;\/Window.DataContext>\n\n    &lt;Grid>\n\n        &lt;Button Content=\"MessageBox\" Margin=\"10,10,657,359\" Height=\"Auto\">\n            &lt;i:Interaction.Triggers>\n                &lt;i:EventTrigger EventName=\"Click\">\n                    &lt;l:LivetCallMethodAction MethodTarget=\"{Binding}\" MethodName=\"ShowMessageBox\" \/>\n                &lt;\/i:EventTrigger>\n            &lt;\/i:Interaction.Triggers>\n        &lt;\/Button>\n        \n        &lt;Button Content=\"Progress\" Margin=\"155,10,512,359\" Height=\"Auto\">\n            &lt;i:Interaction.Triggers>\n                &lt;i:EventTrigger EventName=\"Click\">\n                    &lt;l:LivetCallMethodAction MethodTarget=\"{Binding}\" MethodName=\"ShowProgress\" \/>\n                &lt;\/i:EventTrigger>\n            &lt;\/i:Interaction.Triggers>\n        &lt;\/Button>\n\n    &lt;\/Grid>\n&lt;\/Controls:MetroWindow><\/code><\/pre>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">MainView.xaml.cs<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">namespace WpfApp12.View\n{\n    \/\/\/ &lt;summary>\n    \/\/\/ MainView.xaml \u306e\u76f8\u4e92\u4f5c\u7528\u30ed\u30b8\u30c3\u30af\n    \/\/\/ &lt;\/summary>\n    public partial class MainView : MahApps.Metro.Controls.MetroWindow\n    {\n        public MainView()\n        {\n            InitializeComponent();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">MainViewModel.cs<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">using System;\nusing System.Threading.Tasks;\nusing MahApps.Metro.Controls.Dialogs;\n\nnamespace WpfApp12.ViewModel\n{\n    public class MainViewModel:Livet.ViewModel\n    {\n        public IDialogCoordinator MahAppsDialogCoordinator { get; set; }\n\n        \/\/\/ &lt;summary>\n        \/\/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u30dc\u30c3\u30af\u30b9\u306e\u8868\u793a\n        \/\/\/ &lt;\/summary>\n        public async void ShowMessageBox()\n        {\n            await MahAppsDialogCoordinator.ShowMessageAsync(this, \"ShowMessageBox\", \"ShowMessageBoxText\");\n        }\n\n        \/\/\/ &lt;summary>\n        \/\/\/ \u30d7\u30ed\u30b0\u30ec\u30b9\u30c0\u30a4\u30a2\u30ed\u30b0\u306e\u8868\u793a\n        \/\/\/ &lt;\/summary>\n        public async void ShowProgress()\n        {\n            MetroDialogSettings objDialogSetting = new MetroDialogSettings()\n            {\n                NegativeButtonText = \"\u9589\u3058\u308b\"\n            };\n\n            ProgressDialogController objController = await MahAppsDialogCoordinator.ShowProgressAsync(this, \"ShowProgress\", \"ShowProgressTest\", false, objDialogSetting);\n            objController.Canceled += async (object sender, EventArgs e) =>\n            {\n                await objController.CloseAsync();\n            };\n\n            objController.Minimum = 1;\n            objController.Maximum = 10;\n\n            await Task.Run(() =>\n            {\n                for (int i = 1; i &lt;= 10; i++)\n                {\n                    System.Threading.Thread.Sleep(100);\n\n                    objController.SetProgress(i);\n                    objController.SetMessage(\"Progress:\" + i.ToString());\n\n                    if (i == 10)\n                        objController.SetCancelable(true);\n                }\n            });\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"450\" src=\"http:\/\/marius.main.jp\/software\/blog\/wp-content\/uploads\/2019\/11\/Dialog_1.png\" alt=\"\" class=\"wp-image-499\" srcset=\"https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2019\/11\/Dialog_1.png 800w, https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2019\/11\/Dialog_1-300x169.png 300w, https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2019\/11\/Dialog_1-768x432.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"450\" src=\"http:\/\/marius.main.jp\/software\/blog\/wp-content\/uploads\/2019\/11\/Dialog_2-1.png\" alt=\"\" class=\"wp-image-501\" srcset=\"https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2019\/11\/Dialog_2-1.png 800w, https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2019\/11\/Dialog_2-1-300x169.png 300w, https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2019\/11\/Dialog_2-1-768x432.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>MainView.xaml<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,20],"tags":[35,39,24,29,23],"class_list":["post-497","post","type-post","status-publish","format-standard","hentry","category-c","category-wpf","tag-c","tag-dialog","tag-livet","tag-mahapps","tag-wpf"],"_links":{"self":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=497"}],"version-history":[{"count":4,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions"}],"predecessor-version":[{"id":783,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions\/783"}],"wp:attachment":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}