public MainWindow()
        {
            InitializeComponent();

            viewModel = DataContext as MainWindowViewModel;

            if (!string.IsNullOrEmpty(Properties.Settings.Default.PreviousPrinters))
            {
                previousPrinters = JsonConvert.DeserializeObject <Dictionary <string, string> >(Properties.Settings.Default.PreviousPrinters);
                foreach (string address in previousPrinters.Keys)
                {
                    if (address.Length > 0)
                    {
                        viewModel.RecentlySelectedPrinters.AddAfter(viewModel.RecentlySelectedPrinters.First, new Util.PrinterInfo {
                            Address = address,
                            Model   = previousPrinters[address]
                        });
                    }
                }
            }

            if (previousPrinters == null)
            {
                previousPrinters = new Dictionary <string, string>();
            }

            string savedPrinterIpAddress = Properties.Settings.Default.IpAddress;

            if (!string.IsNullOrEmpty(savedPrinterIpAddress))
            {
                string savedPrinterModel = Properties.Settings.Default.Model;

                Util.PrinterInfo selectedPrinter = new Util.PrinterInfo {
                    Address = savedPrinterIpAddress,
                    Model   = savedPrinterModel
                };
                viewModel.RecentlySelectedPrinters.AddAfter(viewModel.RecentlySelectedPrinters.First, selectedPrinter);
                viewModel.SelectedPrinter = selectedPrinter;
                RefreshTemplates();
            }
            else
            {
                ShowPrinterDiscoveryWindow();
            }
        }
        public void ShowPrinterDiscoveryWindow()
        {
            printerDiscoveryWindow = new PrinterDiscoveryWindow()
            {
                Topmost = true
            };

            if (printerDiscoveryWindow.ShowDialog() == false)
            {
                if (printerDiscoveryWindow != null)
                {
                    Util.PrinterInfo selectedPrinter = printerDiscoveryWindow.SelectedPrinterInfo;
                    if (selectedPrinter.Address != null && selectedPrinter.Model != null && viewModel != null)
                    {
                        LinkedListNode <Util.PrinterInfo> node = viewModel.RecentlySelectedPrinters.First;
                        while (node != null)
                        {
                            Util.PrinterInfo printerInfo = node.Value;
                            if (printerInfo.Address.Equals(selectedPrinter.Address))
                            {
                                if (!printerInfo.Model.Equals(selectedPrinter.Model))
                                {
                                    printerInfo.Model = selectedPrinter.Model;
                                    node.Value        = printerInfo;
                                }
                                SelectedPrinterComboBox.SelectedItem = printerInfo;
                                return;
                            }
                            node = node.Next;
                        }

                        string previousPrinterIp = Properties.Settings.Default.IpAddress;
                        if (previousPrinterIp.Length > 0)
                        {
                            previousPrinters.Add(previousPrinterIp, Properties.Settings.Default.Model);
                        }

                        viewModel.RecentlySelectedPrinters.AddAfter(viewModel.RecentlySelectedPrinters.First, selectedPrinter);
                        viewModel.SelectedPrinter = selectedPrinter;
                    }
                    printerDiscoveryWindow = null;
                }
            }
        }