private void ChangeState() { if (editdisplaycontent == null) { return; } switch (State) { case EditDisplayState.Edit: editdisplaycontent.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding("EditTemplate") { Source = this }); //editdisplaycontent.ContentTemplate = EditTemplate; break; default: editdisplaycontent.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding("DisplayTemplate") { Source = this }); break; } }
protected override DependencyObject GetContainerForItemOverride() { ContentPresenter container = (ContentPresenter)base.GetContainerForItemOverride(); if (ItemTemplate == null) { return(container); } FrameworkElement content = (FrameworkElement)ItemTemplate.LoadContent(); BindingExpression rowBinding = content.GetBindingExpression(Grid.RowProperty); BindingExpression columnBinding = content.GetBindingExpression(Grid.ColumnProperty); if (rowBinding != null) { container.SetBinding(Grid.RowProperty, rowBinding.ParentBinding); } if (columnBinding != null) { container.SetBinding(Grid.ColumnProperty, columnBinding.ParentBinding); } return(container); }
private void CreateCaptionForControl(UIElement control) { DialogPanel.AddCaptionChangedEventHandler(control, this.ControlCaptionChanged); object Caption = DialogPanel.GetCaption(control); if (Caption != null) { UIElement CaptionControl; if (Caption is UIElement) { CaptionControl = (UIElement)Caption; } else { ContentPresenter Presenter = new ContentPresenter(); Presenter.SetBinding(ContentPresenter.ContentProperty, new Binding { Source = control, Path = new PropertyPath(DialogPanel.CaptionProperty), BindsDirectlyToSource = true }); Presenter.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding { BindsDirectlyToSource = true, Source = this, Path = new PropertyPath("CaptionTemplate") }); CaptionControl = Presenter; } this.captionControls.Add(control, CaptionControl); this.AddVisualChild(CaptionControl); } else { //Ignore: there is no caption, This means, the control shall have full width } this.InvalidateMeasure(); }
public TemplatedAdorner(UIElement adornedElement, AdornerLayer adornerLayer) : base(adornedElement) { _adornerLayer = adornerLayer; _contentPresenter = new ContentPresenter(); //绑定内容 var contentBinding = new Binding { Mode = BindingMode.TwoWay, Source = adornedElement, Path = new PropertyPath(MaskAttach.DataContextProperty) }; _contentPresenter.SetBinding(ContentPresenter.ContentProperty, contentBinding); //绑定模板 var contentTemplateBinding = new Binding { Mode = BindingMode.TwoWay, Source = adornedElement, Path = new PropertyPath(MaskAttach.TemplateProperty) }; _contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, contentTemplateBinding); //当控件发生大小变化的时候需要强制刷新,不过加这句效率会有影响 //AdornedElement.LayoutUpdated += AdornedElementLayoutUpdated; //加入层中 _adornerLayer.Add(this); //加入可视树是为了防止点击穿过 AddVisualChild(_contentPresenter); }
private ContentPresenter GetPresenter(object item) { if (item == null) { return(null); } if (!_presenterCache.TryGetValue(item, out var presenter)) { presenter = new ContentPresenter(); presenter.Content = item; presenter.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding(nameof(ContentTemplate)) { Source = this }); presenter.SetBinding(ContentPresenter.ContentTemplateSelectorProperty, new Binding(nameof(ContentTemplateSelector)) { Source = this }); _presenterCache.Add(item, presenter); } return(presenter); }
private void UnmaskHiddenContent() { if (_contentGrid == null) { #if DEBUG throw new InvalidOperationException("Content grid must be present."); #endif return; } if (_contentPresenter != null) { #if DEBUG throw new InvalidOperationException("Unmasking cannot happen twice."); #endif return; } //_hasUnmaskedContent = true; var contentBinding = new Binding("Content") { BindsDirectlyToSource = true, Source = this }; var templateBinding = new Binding("ContentTemplate") { BindsDirectlyToSource = true, Source = this }; _contentPresenter = new ContentPresenter { HorizontalAlignment = HorizontalContentAlignment, VerticalAlignment = VerticalContentAlignment, Margin = Padding, IsHitTestVisible = false, }; _contentPresenter.Loaded += OnContentPresenterLoaded; _contentPresenter.Unloaded += OnContentPresenterUnloaded; _contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, templateBinding); _contentPresenter.SetBinding(ContentPresenter.ContentProperty, contentBinding); _contentGrid.Children.Add(_contentPresenter); _contentGrid.Visibility = Visibility.Visible; _okToShowAfter = DateTime.Now + MinimumLoadingTime; _timeoutAfter = DateTime.Now + TimeoutSpan; // probably don't need this one if (_timeoutTimer == null) { _timeoutTimer = new DispatcherTimer(); _timeoutTimer.Interval = TimeoutSpan; _timeoutTimer.Tick += OnTimeoutTimerTick; } _timeoutTimer.Start(); }
public void SetFileTabDefinition(FileTabDefinition fileTabDefinition) { this.DataContext = fileTabDefinition; if (fileTabDefinition.IsSeparator) { this.Content = new Separator(); this.IsEnabled = false; } else { this.SetBinding(TabItem.HeaderProperty, new Binding { Source = fileTabDefinition, Path = new PropertyPath(FileTabDefinition.HeaderProperty) }); var presenter = new ContentPresenter(); presenter.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding { Source = fileTabDefinition, Path = new PropertyPath(FileTabDefinition.ContentTemplateProperty) }); this.Content = presenter; this.command = fileTabDefinition.Command as RoutedCommand; if (fileTabDefinition.Command != null) { fileTabDefinition.Command.CanExecuteChanged += OnCommandCanExecuteChanged; this.IsEnabled = this.command == null?fileTabDefinition.Command.CanExecute(fileTabDefinition.CommandParameter) : this.command.CanExecute(fileTabDefinition.CommandParameter, fileTabDefinition.CommandTarget); } } }
/// <summary> /// 初始化,创建简易结构 /// </summary> void Init() { _rootGrid = new Grid() { MinWidth = 40d, MinHeight = 40d, Background = Res.默认背景, BorderThickness = new Thickness(1d), BorderBrush = Res.浅灰边框 }; _sv = new ScrollViewer { ZoomMode = ZoomMode.Disabled, HorizontalScrollMode = ScrollMode.Auto, HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, VerticalScrollMode = ScrollMode.Auto, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, }; _pre = new ContentPresenter { FontSize = 15 }; _pre.SetBinding(ContentPresenter.ContentProperty, new Binding { Path = new PropertyPath("Child"), Source = this }); _sv.Content = _pre; _rootGrid.Children.Add(_sv); Content = _rootGrid; Opening += OnOpening; }
public DialogBase() { // You might ask yourself why this is happening... // // It's all because WPF apparently has a bug where if you use the Template property on Window to customize the // visual tree of its content (i.e., put the button tray / progressive disclosure / footnote stuff in), everything // works great *except* you don't get focus visuals for any of the controls. // // So to get around that, we don't mess with the template of the window itself, but instead: // 1) Programmatically create a ContentPresenter and set it as the content of the Window (dialog) // 2) Change the default content property to be "MainContent" (so the xaml for DialogBase derivations looks "normal") // 3) Bind the content presenter to the MainContent property (and the template to MainContentTemplate) // // Viola! Plus the dialogs are now individually customizable via MainContentTemplate. var content = new ContentPresenter() { Focusable = false, Content = new SelfWrapper(this) }; content.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding { Source = this, Path = new PropertyPath(MainContentTemplateProperty) }); this.Content = content; this.buttons = new ObservableCollection <Button>(); this.Loaded += OnLoaded; }
private static UIElement r_2_ctMethod(UIElement parent) { // e_0 element Grid e_0 = new Grid(); e_0.Parent = parent; e_0.Name = "e_0"; RowDefinition row_e_0_0 = new RowDefinition(); row_e_0_0.Height = new GridLength(20F, GridUnitType.Pixel); e_0.RowDefinitions.Add(row_e_0_0); RowDefinition row_e_0_1 = new RowDefinition(); e_0.RowDefinitions.Add(row_e_0_1); // PART_WindowTitleBorder element Border PART_WindowTitleBorder = new Border(); e_0.Children.Add(PART_WindowTitleBorder); PART_WindowTitleBorder.Name = "PART_WindowTitleBorder"; PART_WindowTitleBorder.Background = new SolidColorBrush(new ColorW(255, 255, 255, 255)); // e_1 element ContentPresenter e_1 = new ContentPresenter(); e_0.Children.Add(e_1); e_1.Name = "e_1"; Grid.SetRow(e_1, 1); Binding binding_e_1_Content = new Binding(); e_1.SetBinding(ContentPresenter.ContentProperty, binding_e_1_Content); return e_0; }
private static UIElement r_2_ctMethod(UIElement parent) { // e_0 element Grid e_0 = new Grid(); e_0.Parent = parent; e_0.Name = "e_0"; RowDefinition row_e_0_0 = new RowDefinition(); row_e_0_0.Height = new GridLength(20F, GridUnitType.Pixel); e_0.RowDefinitions.Add(row_e_0_0); RowDefinition row_e_0_1 = new RowDefinition(); e_0.RowDefinitions.Add(row_e_0_1); // PART_WindowTitleBorder element Border PART_WindowTitleBorder = new Border(); e_0.Children.Add(PART_WindowTitleBorder); PART_WindowTitleBorder.Name = "PART_WindowTitleBorder"; PART_WindowTitleBorder.Background = new SolidColorBrush(new ColorW(255, 255, 255, 255)); // e_1 element ContentPresenter e_1 = new ContentPresenter(); e_0.Children.Add(e_1); e_1.Name = "e_1"; Grid.SetRow(e_1, 1); Binding binding_e_1_Content = new Binding(); e_1.SetBinding(ContentPresenter.ContentProperty, binding_e_1_Content); return(e_0); }
private void UnmaskHiddenContent() { // LIPEx // if (_contentGrid == null) // { //#if DEBUG // throw new InvalidOperationException("Content grid must be present."); //#endif // return; // } // LPIEx // if (_contentPresenter != null) // { //#if DEBUG // throw new InvalidOperationException("Unmasking cannot happen twice."); //#endif // return; // } //_hasUnmaskedContent = true; var contentBinding = new Binding("Content") { BindsDirectlyToSource = true, Source = this }; var templateBinding = new Binding("ContentTemplate") { BindsDirectlyToSource = true, Source = this }; _contentPresenter = new ContentPresenter { HorizontalAlignment = HorizontalContentAlignment, VerticalAlignment = VerticalContentAlignment, Margin = Padding, IsHitTestVisible = false, }; _contentPresenter.Loaded += OnContentPresenterLoaded; _contentPresenter.Unloaded += OnContentPresenterUnloaded; _contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, templateBinding); _contentPresenter.SetBinding(ContentPresenter.ContentProperty, contentBinding); _contentGrid.Children.Add(_contentPresenter); _contentGrid.Visibility = Visibility.Visible; _okToShowAfter = DateTime.Now + MinimumLoadingTime; }
public PageClone() { content = new ContentPresenter(); content.SetBinding(ContentPresenter.ContentProperty, new Binding("Content") { Source = this }); AddVisualChild(content); }
protected override FrameworkElement GenerateEditingElementCore() { var control = new ContentPresenter { ContentTemplate = this.EditingTemplate }; control.SetBinding(ContentPresenter.ContentProperty, this.Binding); return(control); }
private UIElement CreateControls(UIElement parent) { ContentPresenter p = new ContentPresenter(); p.Parent = parent; p.SetBinding(ContentPresenter.ContentProperty, new Binding() { Source = this, SourceDependencyProperty = Window.ContentProperty }); return(p); }
/// <summary> /// Setup a new binding on a child content presenter. /// </summary> /// <param name="view">The view.</param> /// <param name="bindingSource">The source of the binding.</param> /// <param name="path">The binding path.</param> protected void SetupBinding(ContentPresenter view, object bindingSource, string path) { //view.ClearValue(ContentPresenter.ContentProperty); if (bindingSource != null) { var b = new Binding(path); b.Source = bindingSource; view.SetBinding(ContentPresenter.ContentProperty, b); } }
public WatermarkAdorner(UIElement adornedElement) : base(adornedElement) { contentPresenter = new ContentPresenter(); contentPresenter.VerticalAlignment = VerticalAlignment.Stretch; contentPresenter.HorizontalAlignment = HorizontalAlignment.Stretch; contentPresenter.SetBinding(ContentPresenter.ContentProperty, new Binding(nameof(Content)) { Source = this, }); Register(); }
private void AddTickmark(double position) { ContentPresenter c = new ContentPresenter(); c.SetValue(PositionProperty, position); c.SetBinding(ContentPresenter.ContentTemplateProperty, new System.Windows.Data.Binding() { Source = this, BindsDirectlyToSource = true, Path = new PropertyPath("TickMarkTemplate") }); Children.Add(c); }
private ContentAdorner(UIElement adornedElement) : base(adornedElement) { _children = new VisualCollection(this); var contentPresenter = new ContentPresenter(); contentPresenter.SetBinding(ContentPresenter.ContentProperty, new Binding { Path = new PropertyPath(AdornerContentProperty), Source = adornedElement }); contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding { Path = new PropertyPath(AdornerContentTemplateProperty), Source = adornedElement }); _child = contentPresenter; _children.Add(_child); }
public HierarchicalDataTemplate() { // Workaround to avoid NullReferenceException since the compiler does not handle HierarchicalDataTemplate yet. this._methodToInstantiateFrameworkTemplate = (control) => { ContentPresenter presenter = new ContentPresenter(); presenter.SetBinding(ContentControl.ContentProperty, new Binding()); return(new TemplateInstance() { TemplateContent = presenter, }); }; }
private void TemplatedWindowControl_Loaded(object sender, RoutedEventArgs e) { // Set Zindex Panel parent = ((Panel)this.Parent); FrameworkElement myElement = this; int myZ = Canvas.GetZIndex(myElement); int ZWeAreChecking = 0; int maxZ = 0; for (int i = 0; i < parent.Children.Count; i++) { FrameworkElement childWeAreChecking = parent.Children[i] as FrameworkElement; ZWeAreChecking = Canvas.GetZIndex(childWeAreChecking); if (maxZ < ZWeAreChecking) { maxZ = ZWeAreChecking; } } Canvas.SetZIndex(myElement, maxZ + 1); // Get initial opacity setting double initialOpacity = this.Opacity; // Reset opacity to 1.0 this.Opacity = 1.0; // Set slider to initial opacity if (initialOpacity < 0.25) { initialOpacity = 0.25; } _sliderOpacity.Value = initialOpacity * 100; // Set the binding between the opacity slider and the opacity of _contentPresenter Binding binding = new Binding(); binding.Source = _sliderOpacity; binding.Path = new PropertyPath("Value"); binding.Mode = BindingMode.TwoWay; binding.Converter = new Converters.OpacityBindingConverter(); _contentPresenter.SetBinding(OpacityProperty, binding); // Check if content is TextBox if (this.Content != null) { if (this.Content.GetType() == typeof(TextBox)) { ContentIsTextbox = true; } } }
// Be sure to call the base class constructor. public DragAdorner(TreeViewEx treeViewEx, DragContent content) : base(treeViewEx) { layer = AdornerLayer.GetAdornerLayer(treeViewEx); layer.Add(this); contentPresenter = new ContentPresenter(); contentPresenter.Content = content; Binding b = new Binding("DragTemplate"); b.Source = treeViewEx; b.Mode = BindingMode.OneWay; contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, b); }
private static FrameworkElement ExtractGeneric(DisplayOption option) { var ctrl = new ContentPresenter { Margin = new Thickness(3) }; ctrl.SetBinding(ContentPresenter.ContentProperty, new Binding(option.PropertyName)); if (option.Wide) { ctrl.SetValue(Grid.ColumnSpanProperty, 2); } return(ctrl); }
public void RealizeContent() { if (_contentPresenter != null) { return; // throw new InvalidOperationException("Already realized!"); // probably want to not throw in the future, but just no-op out? } Debug("RealizeContent"); _contentPresenter = new ContentPresenter { HorizontalAlignment = HorizontalContentAlignment, VerticalAlignment = VerticalContentAlignment, Margin = Padding, IsHitTestVisible = false, }; _contentPresenter.Loaded += OnContentPresenterLoaded; _contentPresenter.Unloaded += OnContentPresenterUnloaded; _contentPresenter.SetBinding( ContentPresenter.ContentTemplateProperty, new Binding("ContentTemplate") { BindsDirectlyToSource = true, Source = this }); _contentPresenter.SetBinding( ContentPresenter.ContentProperty, new Binding("Content") { BindsDirectlyToSource = true, Source = this }); _contentPanel.Children.Add(_contentPresenter); _contentPanel.Visibility = Visibility.Visible; // ? is this one needed ? }
/// <summary>Initializes a new instance of the <see cref="SplitContainer"/> class.</summary> public SplitContainer() { SplitterPresenter = new ContentPresenter(); AddLogicalChild(SplitterPresenter); AddVisualChild(SplitterPresenter); SetSplitterTemplate(SplitterTemplate); SplitterPresenter.SetBinding(StyleProperty, new Binding() { Source = this, Path = new PropertyPath(SplitterPresenterStyleProperty) }); bool designMode = DesignerProperties.GetIsInDesignMode(this); VerifyLicense(designMode); }
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { ContentPresenter contentPresenter = element as ContentPresenter; CategoryEditor categoryEditor = item as CategoryEditor; if (contentPresenter != null && categoryEditor != null) { contentPresenter.SetBinding(ContentPresenter.ContentProperty, (BindingBase) new Binding("DataContext.Category") { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(CategoryLayoutContainer), 1) }); contentPresenter.ContentTemplate = categoryEditor.get_EditorTemplate(); } base.PrepareContainerForItemOverride(element, item); }
private void SetupBinding(ContentPresenter view, string property) { var script = this.SubAndSuperscript; #if !SILVERLIGHT BindingOperations.ClearBinding(view, ContentPresenter.ContentProperty); #endif if (script != null) { var b = new Binding(property); b.Source = script; view.SetBinding(ContentPresenter.ContentProperty, b); } }
protected virtual object LoadDlgContent() { ContentPresenter content = new ContentPresenter() { VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, }; Binding contentBinding = new Binding() { Path = new PropertyPath("SelectedContent"), Source = this }; content.SetBinding(ContentPresenter.ContentProperty, contentBinding); return(content); }
/// <summary> /// Gets the read-only element that is bound to the column. /// </summary> /// <param name="cell">The cell that will contain the generated element.</param> /// <param name="dataItem">The data item that is represented by the row that contains the intended cell.</param> /// <returns>A new read-only element that is bound to the value of the column.</returns> protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem) { var binding = new Binding(((Binding)Binding).Path.Path) // comment this out to fix the bug { Source = dataItem }; var content = new ContentPresenter { ContentTemplate = CellTemplate }; content.SetBinding(ContentControl.ContentProperty, binding); return(content); }
public BlendEffectBox() { _effectTopPresenter = new ContentPresenter(); ActualContent = _effectTopPresenter; _effectBottomPresenter = new ContentPresenter(); _effectBottomPresenter.SetBinding(ContentPresenter.ContentProperty, new Binding(ContentProperty.Name) { Source = this }); var effects = new ObservableCollection <Effect>(); effects.CollectionChanged += OnEffectsChanged; Effects = effects; }
/// <summary> /// Binds the ContentPresenter's Content property to the Binding set on this control. /// </summary> private void UpdateBindings() { if (_content == null) { return; } if (_binding != null) { _content.SetBinding(ContentPresenter.ContentProperty, _binding); } else { _content.ClearValue(ContentPresenter.ContentProperty); } }
public InsertAdorner(TreeViewExItem treeViewItem, InsertContent content) : base(GetParentBorder(treeViewItem)) { this.treeViewItem = treeViewItem; layer = AdornerLayer.GetAdornerLayer(AdornedElement); layer.Add(this); contentPresenter = new ContentPresenter(); contentPresenter.HorizontalAlignment = HorizontalAlignment.Stretch; contentPresenter.Width = treeViewItem.ActualWidth; contentPresenter.Content = content; Binding b = new Binding("InsertTemplate"); b.Source = treeViewItem.ParentTreeView; b.Mode = BindingMode.OneWay; contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, b); content.InsertionMarkerBrush = treeViewItem.ParentTreeView.InsertionMarkerBrush; content.Item = treeViewItem; }