/*=========================*/ #endregion #region Public Methods /*=========================*/ /// <summary> /// /// </summary> /// <param name="tempContent"> /// A version (copy) of the object that the input controls will directly affect, based on bindings in the ContentTemplate. /// This will be applied to the Content property and can be used in the ApplyingChanges event /// handler to validate the changes. /// </param> /// <param name="targetContent"> /// The object to which changes will be applied when ApplyChanges is called. /// </param> public void BeginEdit(object tempContent, object targetContent) { if (this.IsOpen) { throw new InvalidOperationException("Dialog is already open"); } // Don't mark as changed while applying changes SetValue(TargetContentProperty, targetContent); this.Content = tempContent; ApplyBatchCheckboxes(false); // Force a focus of the selected tab, if present TabControl tabs = VisualTree.GetChild <TabControl>(this); if (tabs != null) { for (int i = 0; i < tabs.Items.Count; i++) { TabItem tab = tabs.ItemContainerGenerator.ContainerFromIndex(i) as TabItem; if (tab != null && tab.IsSelected) { tab.RaiseEvent(new RoutedEventArgs(TabItem.GotFocusEvent)); break; } } } IsOpen = true; }
/// <summary> /// /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); // Apply event handlers if available _buttonOk = VisualTree.GetChild <Button>(this, "_buttonOK"); _buttonCancel = VisualTree.GetChild <Button>(this, "_buttonCancel"); _buttonApply = VisualTree.GetChild <Button>(this, "_buttonApply"); if (_buttonOk != null) { _buttonOk.Click += new RoutedEventHandler(buttonOK_Click); } if (_buttonCancel != null) { _buttonCancel.Click += new RoutedEventHandler(buttonCancel_Click); } if (_buttonApply != null) { _buttonApply.Click += new RoutedEventHandler(buttonApply_Click); } if (_bindings != null && _bindings.Count == 0) { GetDialogFieldBindings(); } }
void FloatingDialog_Loaded(object sender, RoutedEventArgs e) { if (App.InDesignMode) { return; } VisualTree.GetParent <Grid>(this).Children.Remove(this); App.CurrentPage.Window.FloatingDialogContainer.Children.Add(this); }
void AutocompleteCombo_Loaded(object sender, RoutedEventArgs e) { _textbox = VisualTree.GetChild <TextBox>(this); if (_textbox != null) { _textbox.TextChanged += new TextChangedEventHandler(_textbox_TextChanged); } //if (ItemsSourceRequired != null) // ItemsSourceRequired(this, EventArgs.Empty); }
/// <summary> /// /// </summary> private void _listView_SizeChanged(object sender, SizeChangedEventArgs e) { // Only relevant to grid views if (!(_listView.View is GridView)) { return; } GridView grid = _listView.View as GridView; // Only relevant for width if (e != null && !e.WidthChanged) { return; } // Get all AutoSize columns List <GridViewColumn> columns = new List <GridViewColumn>(); double specifiedWidth = 0; foreach (GridViewColumn col in grid.Columns) { if ((bool)col.GetValue(AutoSizeProperty)) { columns.Add(col); } else { specifiedWidth += col.ActualWidth; } } // Calculate //ScrollViewer scroll = (ScrollViewer) VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(_listView, 0), 0); //ItemsPresenter iPresenter = scroll.Content as ItemsPresenter; ItemsPresenter iPresenter = VisualTree.GetChild <ItemsPresenter>(_listView); ScrollBar scrollBar = VisualTree.GetChild <ScrollBar>(_listView); double newWidth = (iPresenter.ActualWidth - scrollBar.Width - specifiedWidth - 20) / columns.Count; // Give them a fair share of the remaining space foreach (GridViewColumn col in columns) { if (newWidth >= 0) { col.Width = newWidth; } } }
/// <summary> /// Gets the dialog field bindings starting from the content presenter /// </summary> void GetDialogFieldBindings() { ContentPresenter contentPresenter = VisualTree.GetChild <ContentPresenter>(this, "_contentPresenter"); // Get the bindings when a template is applied if (contentPresenter == null) { return; } _scannedControls = new List <DependencyObject>(); // Recursively find all bindings currently available GetDialogFieldBindings(contentPresenter); }
public override Style SelectStyle(object item, DependencyObject container) { ListTable tbl = VisualTree.GetParent <ListTable>(container); // buggy //int index = tbl.ListView.ItemContainerGenerator.IndexFromContainer(container); //string alternate = index % 2 == 0 ? string.Empty : "-alternate"; string alternate = null; if (tbl.ChildItemTypes != null && tbl.ChildItemTypes.Contains(item.GetType())) { return(tbl.ListView.FindResource(String.Format("ChildItemStyle{0}", alternate)) as Style); } else { return(tbl.ListView.FindResource(String.Format("ParentItemStyle{0}", alternate)) as Style); } }
private void ApplyBatchCheckboxes(bool createOnly) { // do not use foreach beacuse it causes inner delegates to work with the wrong object (enumerator.Current) for (int i = 0; i < _bindings.Count; i++) { BEData bedata = _bindings[i]; // In batch mode, attach a checkbox to this control for marking it as 'please override' if (bedata.Obj is Control && ((Control)bedata.Obj).Parent is StackPanel && !GetReadOnlyField(bedata.Obj)) { Control control = (Control)bedata.Obj; StackPanel stackPanel = (StackPanel)control.Parent; CheckBox checkbox = VisualTree.GetChild <CheckBox>(stackPanel, "__batch__cb"); bool created = false; if (checkbox == null && this.IsBatch) { checkbox = new CheckBox(); checkbox.Name = "__batch__cb"; checkbox.ToolTip = "Check this to override the value of this field for all selected items"; checkbox.IsChecked = false; checkbox.Style = (Style)App.Current.Resources["FormFieldBatchCheckbox"]; Action <object, RoutedEventArgs> del = delegate(object sender, RoutedEventArgs e) { bedata.ShouldBatchApply = control.IsEnabled = checkbox.IsChecked.Value; }; checkbox.Checked += new RoutedEventHandler(del); checkbox.Unchecked += new RoutedEventHandler(del); stackPanel.Children.Add(checkbox); created = true; } if (checkbox != null && (!createOnly || created)) { checkbox.IsChecked = false; checkbox.Visibility = IsBatch ? Visibility.Visible : Visibility.Collapsed; control.IsEnabled = !IsBatch; } } } }