Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 应用程序启动时不再显示消息框_C#_Windows Runtime - Fatal编程技术网

C# 应用程序启动时不再显示消息框

C# 应用程序启动时不再显示消息框,c#,windows-runtime,C#,Windows Runtime,当我的应用程序启动时,会显示一个消息框。如何防止它再次显示,以便当用户点击“不再显示”按钮时,消息框在下次打开时不会启动 async protected override void OnLaunched(LaunchActivatedEventArgs e) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app

当我的应用程序启动时,会显示一个消息框。如何防止它再次显示,以便当用户点击“不再显示”按钮时,消息框在下次打开时不会启动

            async protected override void OnLaunched(LaunchActivatedEventArgs e)
        {

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                // Set the default language
                rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();


            MessageDialog md = new MessageDialog("This is a MessageDialog", "Title");
            bool? result = null;
            md.Commands.Add(
               new UICommand("OK", new UICommandInvokedHandler((cmd) => result = true)));
            md.Commands.Add(
               new UICommand("Don't show this again", new UICommandInvokedHandler((cmd) => result = false)));

            await md.ShowAsync();
            if (result == true)
            {
                // do something    
            }
            else if (result == false)
            {
                // do something    
            }

        }

只需在自定义消息框中添加一个标志。如果用户选择“不再显示”,则存储该标志。接下来启动并需要显示此特定消息框,请检查标志。

您必须记录用户选择该选项的位置。有很多方法可以实现这一点

一个简单的策略是创建一个表示所有用户选择的对象。当用户做出选择时,更新该对象并将其序列化为文件。当应用程序首次加载时,从文件中反序列化该对象,以便您可以使用以前的选择


当用户点击“不再显示”按钮时,更新配置对象以记录选择。

有很多方法可以做到这一点。但在所有这些选项中,您需要将用户选择存储在某个位置。你可以把这个储存在

数据库表,将设置与唯一的用户ID(如LoginID)关联 首选项XML文件: 作为项目中的一个设置: 作为注册表项: INI文件 你可能想看看