本文整理汇总了C#中MainWindow.Close方法的典型用法代码示例。如果您正苦于以下问题:C# MainWindow.Close方法的具体用法?C# MainWindow.Close怎么用?C# MainWindow.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MainWindow
的用法示例。
在下文中一共展示了MainWindow.Close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var window = new MainWindow();
var viewModel =
Bootstrapper.CreateContainer(ConfigurationManager.AppSettings["modules"].Split(';')).Resolve
<MainWindowViewModel>();
// When the ViewModel asks to be closed,
// close the window.
EventHandler handler = null;
handler = delegate
{
viewModel.RequestClose -= handler;
window.Close();
};
viewModel.RequestClose += handler;
// Allow all controls in the window to
// bind to the ViewModel by setting the
// DataContext, which propagates down
// the element tree.
window.DataContext = viewModel;
window.Show();
}
示例2: OnStartup
protected override void OnStartup(System.Windows.StartupEventArgs e)
{
base.OnStartup(e);
var window = new MainWindow();
this.MainWindow = window;
this.ShutdownMode = ShutdownMode.OnMainWindowClose;
var vm = new MainWindowViewModel(new WindowsDialogServiceFactory());
vm.RequestClose += (sender, eArgs) =>
{
window.Close();
};
window.DataContext = vm;
window.Show();
}
示例3: Main
public static void Main(string[] args)
{
var app = new App { ShutdownMode = ShutdownMode.OnLastWindowClose };
app.InitializeComponent();
var tempWindowToGetDispatcher = new MainWindow();
var container = new Container(x => x.AddRegistry<AppRegistry>());
container.Configure(x => x.For<Dispatcher>().Add(tempWindowToGetDispatcher.Dispatcher));
container.GetInstance<StartupController>();
var factory = container.GetInstance<WindowFactory>();
var window = factory.Create();
tempWindowToGetDispatcher.Close();
window.Show();
app.Run();
}
示例4: ApplicationStartup
/// <summary>
/// The startup of the application.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.Windows.StartupEventArgs"/> instance containing the event data.</param>
private void ApplicationStartup(object sender, StartupEventArgs e)
{
var mainWindow = new MainWindow();
var catalog = new AggregateCatalog(new DirectoryCatalog("."), new AssemblyCatalog(Assembly.GetExecutingAssembly()));
var container = new CompositionContainer(catalog);
var modules = container.GetExportedValues<IModule>();
var viewModel = new MainWindowViewModel(modules);
//close stuff
EventHandler handler = null;
handler = delegate
{
viewModel.RequestClose -= handler;
mainWindow.Close();
};
viewModel.RequestClose += handler;
mainWindow.DataContext = viewModel;
mainWindow.Show();
}
示例5: Init
public async Task<bool?> Init(MetroWindow win)
{
try
{
parentWindow = win as MainWindow;
authMgr = new Manager();
authMgr["consumer_key"] = ConsumerKey;
authMgr["consumer_secret"] = ConsumerSecret;
authMgr.AcquireRequestToken(RequestTokenURL, "POST");
MetroDialogSettings settings = new MetroDialogSettings()
{
AnimateHide = true,
AnimateShow = true,
AffirmativeButtonText = "확인",
NegativeButtonText = "종료"
};
MessageDialogResult result = await DialogManager.ShowMessageAsync(parentWindow, "인증", "인증을 위해 웹브라우저를 통해 트위터에 로그인합니다.",
MessageDialogStyle.AffirmativeAndNegative, settings);
if (result == MessageDialogResult.Affirmative)
{
System.Diagnostics.Process.Start($"{RequestPinURL}{authMgr["token"]}");
settings = new MetroDialogSettings()
{
AnimateHide = true,
AnimateShow = true,
AffirmativeButtonText = "인증",
NegativeButtonText = "취소 및 종료"
};
string pin = await DialogManager.ShowInputAsync(parentWindow, "PIN", "웹브라우저 상에 표시된 PIN을 입력합니다.", settings);
try
{
authMgr.AcquireAccessToken(AccessTokenURL, "POST", pin);
}
catch(Exception ex)
{
parentWindow.Close();
}
IsInit = true;
// Get Screen Name
dynamic obj = await GetJson("https://api.twitter.com/1.1/account/settings.json", "GET");
string name = obj.screen_name;
// GetProfile
dynamic json = await GetJson($"https://api.twitter.com/1.1/users/show.json?screen_name={name}", "GET");
parentWindow.UserNameBlock.Text = json.name;
parentWindow.ScreenNameBlock.Text = $"@{json.screen_name}";
parentWindow.ProfileDescBlock.Text = json.description;
string imageUrl = json.profile_image_url;
ProfileImage = new BitmapImage();
ProfileImage.BeginInit();
ProfileImage.UriSource = new Uri(imageUrl.Replace("_normal", ""));
ProfileImage.DownloadCompleted +=
(s, ev) => OnPropertyChanged("ProfileImage");
ProfileImage.EndInit();
}
else
{
parentWindow.Close();
}
return IsInit;
}
catch (Exception e)
{
await DialogManager.ShowMessageAsync(parentWindow, "Error", $"= Message{e.Message}\n\n= Stack Trace\n{e.StackTrace}");
IsInit = false;
return false;
}
}
示例6: OpenSettings
public async void OpenSettings(object sender = null, EventArgs e = null)
{
if (SettingsWindow != null)
{
SettingsWindow.Focus();
return;
}
var kc = new KonamiCodeStateMachine();
SettingsWindow = new MainWindow(Data, Poller);
SettingsWindow.KeyDown += (o, args) => kc.KeyPressed(args.Key);
if (PollerService.IsRunning)
await PollerService.Stop();
kc.KonamiCodeEntered += o =>
{
SettingsWindow.Close();
OpenConsole();
};
try
{
SettingsWindow.ShowDialog(); //TODO: Win32Exception The Operation Completed Successfully
}
catch (Win32Exception) { }
PollerService.Start();
_notifyIcon.ShowBalloonTip(2000, "Jenkins Observer", "Polling in Background", ToolTipIcon.Info);
SettingsWindow = null;
}