private void InitializeDataContext(Configuration configuration) { Buttons[] buttons = Enum.GetValues(typeof(Buttons)) .OfType <Buttons>() .ToArray(); string[] skins = Directory.GetDirectories(BCEnvironment.SkinDirectory) .Select(Path.GetFileName) .ToArray(); var backgrounds = new List <Color>(_defaultBackgrounds); var refreshRates = new List <int>(_defaultRefreshRates); var buttonsTransaction = new PropertyTransaction <Buttons>(configuration, nameof(Configuration.Buttons)); var skinTransaction = new PropertyTransaction <string>(configuration, nameof(Configuration.Skin)); var backgroundTransaction = new PropertyTransaction <Color?>(configuration, nameof(Configuration.Background)); var refreshRateTransaction = new PropertyTransaction <int?>(configuration, nameof(Configuration.RefreshRate)); var topMostTransaction = new PropertyTransaction <bool>(configuration, nameof(Configuration.TopMost)); if (configuration.Background.HasValue && !backgrounds.Contains(configuration.Background.Value)) { backgrounds.Add(configuration.Background.Value); } if (configuration.RefreshRate.HasValue && !refreshRates.Contains(configuration.RefreshRate.Value)) { refreshRates.Add(configuration.RefreshRate.Value); } _displaySettingTransaction = new TransactionGroup( buttonsTransaction, skinTransaction, backgroundTransaction, refreshRateTransaction, topMostTransaction); _model = new SettingWindowModel { Keys = _inputModels[0], CancelCommand = new ActionCommand(OnCancelCommandExecuted), SaveCommand = new ActionCommand(OnSaveCommandExecuted), ButtonItems = buttons, Buttons = buttonsTransaction, SkinItems = skins, Skin = skinTransaction, BackgroundItems = backgrounds, Background = backgroundTransaction, RefreshRateItems = refreshRates, RefreshRate = refreshRateTransaction, TopMostItems = _defaultBooleans, TopMost = topMostTransaction }; DataContext = _model; }
public SettingWindow() { InitializeComponent(); pscomm = App.Current.Resources["PSCommDataSource"] as PSCommModel; ComPortBox.IsEnabled = true; DataContext = new SettingWindowModel(); string[] ports = SerialPort.GetPortNames(); // Display each port name to the console. foreach (string port in ports) { if (port.Substring(0, 3) == "COM") { ComPortBox.Items.Add(port); } } ComPortBox.SelectedIndex = 0; }