Пример #1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= OnLoaded;

            var mainWindowViewModel = Window.GetWindow(this)?.DataContext as MainWindowViewModel;

            if (mainWindowViewModel is null)
            {
                return;
            }

            // Binding in xaml will not work because MainWindowViewModel may be null when Options is instantiated.
            var booleanInverseConverter = new BooleanInverseConverter();

            PathGroupBox.SetBinding(
                UIElement.IsEnabledProperty,
                new Binding(nameof(MainWindowViewModel.IsCheckOrCopyOngoing))
            {
                Source    = mainWindowViewModel,
                Mode      = BindingMode.OneWay,
                Converter = booleanInverseConverter
            });

            FileGroupBox.SetBinding(
                UIElement.IsEnabledProperty,
                new Binding(nameof(MainWindowViewModel.IsCheckOrCopyOngoing))
            {
                Source    = mainWindowViewModel,
                Mode      = BindingMode.OneWay,
                Converter = booleanInverseConverter
            });

            ChooseDeleteOnCopyButton.SetBinding(
                SlidingToggleButton.IsCheckedCopyProperty,
                new Binding(nameof(MainWindowViewModel.IsBrowserOpen))
            {
                Source = mainWindowViewModel,
                Mode   = BindingMode.OneWayToSource,
            });

            LanguageComboBox.SetBinding(
                UIElement.IsEnabledProperty,
                new Binding(nameof(MainWindowViewModel.IsCheckOrCopyOngoing))
            {
                Source    = mainWindowViewModel,
                Mode      = BindingMode.OneWay,
                Converter = booleanInverseConverter
            });
        }
Пример #2
0
        public Options(MainWindow mainWindow)
        {
            InitializeComponent();

            _mainWindowViewModel = mainWindow?.DataContext as MainWindowViewModel ?? throw new InvalidOperationException();
            this.DataContext     = new OptionsViewModel(_mainWindowViewModel.Settings);

            // If Options is defined in MainWindow's xaml, it will be instantiated before MainWindowViewModel
            // and so binding to MainWindowViewModel will not work.
            var booleanInverseConverter = new BooleanInverseConverter();

            PathGroupBox.SetBinding(
                UIElement.IsEnabledProperty,
                new Binding(nameof(MainWindowViewModel.IsCheckOrCopyOngoing))
            {
                Source    = _mainWindowViewModel,
                Mode      = BindingMode.OneWay,
                Converter = booleanInverseConverter
            });

            FileGroupBox.SetBinding(
                UIElement.IsEnabledProperty,
                new Binding(nameof(MainWindowViewModel.IsCheckOrCopyOngoing))
            {
                Source    = _mainWindowViewModel,
                Mode      = BindingMode.OneWay,
                Converter = booleanInverseConverter
            });

            LanguageComboBox.SetBinding(
                UIElement.IsEnabledProperty,
                new Binding(nameof(MainWindowViewModel.IsCheckOrCopyOngoing))
            {
                Source    = _mainWindowViewModel,
                Mode      = BindingMode.OneWay,
                Converter = booleanInverseConverter
            });
        }