Пример #1
0
        /// <summary>
        /// Event handler called when the WPF UserControl is loaded.
        /// The wrapping window listens to the CanSave and CanClose property changed events.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void SettingsControlLoaded(object sender, System.Windows.RoutedEventArgs e)
        {
            // We need to update the 'Save' (CanSave) and 'Cancel' (CanCancel) buttons in the UI.
            this.OnPropertyChanged("CanSave");
            this.OnPropertyChanged("CanClose");

            // Locate the Save button in the frame wrapping us
            FrameworkElement SaveButton;

            SaveButton = (FrameworkElement)VisualTreeHelper.GetParent(this.SettingsControl);
            while (SaveButton.Name != "AppContent")
            {
                SaveButton = (FrameworkElement)VisualTreeHelper.GetParent(SaveButton);
            }

            SaveButton = (FrameworkElement)VisualTreeHelper.GetParent(SaveButton);    // returns Grid
            SaveButton = (FrameworkElement)VisualTreeHelper.GetChild(SaveButton, 1);  // returns ButtonsPanelBorder
            SaveButton = (FrameworkElement)VisualTreeHelper.GetChild(SaveButton, 0);  // returns ButtonsPanel
            SaveButton = (FrameworkElement)VisualTreeHelper.GetChild(SaveButton, 1);  // returns Yes Button aka Done

            // Bind the IsDefault property of the Save button
            // to the SelectedProject property of the UI's listbox.
            // This will cause IsDefault to be set to true when the user
            // selects a project from the list.
            Binding myBinding = new Binding("SelectedItem");

            myBinding.Source             = ((JiraConnectionUI)this.SettingsControl).lbProjects;
            myBinding.Path               = new PropertyPath("SelectedItem");
            myBinding.Converter          = new SelectedProjectToBoolConverter();
            myBinding.ConverterParameter = "False";
            SaveButton.SetBinding(Button.IsDefaultProperty, myBinding);
        }
        private void CreateBindings()
        {
            FileTextBox.SetBinding(TextBox.TextProperty, new Binding("File")
            {
                Source = _model,
                Mode   = BindingMode.OneWay
            });

            ItemComboBox.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("Items")
            {
                Source = _model,
                Mode   = BindingMode.OneWay
            });
            ItemComboBox.SetBinding(Selector.SelectedItemProperty, new Binding("Item")
            {
                Source = _model,
                Mode   = BindingMode.TwoWay
            });
            _model.ItemChanged += SelectedItemChanged;

            SaveButton.SetBinding(IsEnabledProperty, new Binding("SaveButtonEnabled")
            {
                Source = _model,
                Mode   = BindingMode.OneWay
            });
        }