private void UpdateLayout(Size newSize) { double spaceX = newSize.Width - Padding.Left - Padding.Right; if (spaceX < 0) { spaceX = 0; } double spaceY = newSize.Height - Padding.Top - Padding.Bottom; if (spaceY < 0) { spaceY = 0; } if (spaceY > spaceX) { _contentPresenter.Width = _contentPresenter.Height = spaceX; _contentPresenter.SetValue(Canvas.LeftProperty, Padding.Left); _contentPresenter.SetValue(Canvas.TopProperty, Padding.Top + (spaceY - spaceX) / 2.0); } else { _contentPresenter.Width = _contentPresenter.Height = spaceY; _contentPresenter.SetValue(Canvas.LeftProperty, Padding.Left + (spaceX - spaceY) / 2.0); _contentPresenter.SetValue(Canvas.TopProperty, Padding.Top); } }
/// <summary> /// Creates the container for an item. /// </summary> /// <param name="item">The item.</param> /// <returns>The created container control.</returns> protected virtual IControl?CreateContainer(object item) { var result = item as IControl; if (result == null) { result = new ContentPresenter(); result.SetValue(ContentPresenter.ContentProperty, item, BindingPriority.Style); if (ItemTemplate != null) { result.SetValue( ContentPresenter.ContentTemplateProperty, ItemTemplate, BindingPriority.Style); } } if (ItemContainerTheme != null) { result.SetValue( StyledElement.ThemeProperty, ItemContainerTheme, BindingPriority.TemplatedParent); } return(result); }
internal void Dispose() { m_symbolPresenter.SetValue(ContentPresenter.ContentTemplateProperty, null); m_symbolPresenter.SetValue(ContentPresenter.ContentProperty, null); this.adornment = null; this.PredefinedSymbol = null; this.m_symbolPresenter = null; }
internal void HandleFlyoutStatusChange(Flyout flyout) { if (flyout.Position == Position.Right && flyout.IsOpen) { WindowCommandsPresenter.SetValue(Panel.ZIndexProperty, 3); } else { WindowCommandsPresenter.SetValue(Panel.ZIndexProperty, 1); //in the style, the default is 1 } }
private void LoadTemplateIntoGridView(RadGridView gridView) { contentPresenter.IsHitTestVisible = false; contentPresenter.DataContext = this; contentPresenter.ContentTemplate = this.EmptyDataTemplate; Grid rootGrid = gridView.FindChildByType <Grid>();//.ChildrenOfType<Grid>()[0]; contentPresenter.SetValue(Grid.RowProperty, 2); contentPresenter.SetValue(Grid.RowSpanProperty, 2); contentPresenter.SetValue(Grid.ColumnSpanProperty, 2); contentPresenter.SetValue(Border.MarginProperty, new Thickness(0, 27, 0, 0)); rootGrid.Children.Add(contentPresenter); }
private void LoadTemplateIntoGridView(RadGridView gridView) { ContentPresenter.IsHitTestVisible = false; ContentPresenter.DataContext = this; ContentPresenter.ContentTemplate = EmptyDataTemplate; var rootGrid = gridView.ChildrenOfType <Grid>().FirstOrDefault(); ContentPresenter.SetValue(Grid.RowProperty, 2); ContentPresenter.SetValue(Grid.RowSpanProperty, 2); ContentPresenter.SetValue(Grid.ColumnSpanProperty, 2); ContentPresenter.SetValue(FrameworkElement.MarginProperty, new Thickness(0, 27, 0, 0)); rootGrid.Children.Add(ContentPresenter); }
private void StartTransition(object oldContent, object newContent) { // both presenters must be available, otherwise a transition is useless. if (currentContentPresentationSite != null && previousContentPresentationSite != null) { if (RestartTransitionOnContentChange) { //this.CurrentTransition.Completed -= this.OnTransitionCompleted; } currentContentPresentationSite.SetValue(ContentPresenter.ContentProperty, newContent); previousContentPresentationSite.SetValue(ContentPresenter.ContentProperty, oldContent); // and start a new transition if (!IsTransitioning || RestartTransitionOnContentChange) { //if (this.RestartTransitionOnContentChange) //{ // this.CurrentTransition.Completed += this.OnTransitionCompleted; //} IsTransitioning = true; //VisualStateManager.GoToState(this, NormalState, false); //VisualStateManager.GoToState(this, this.GetTransitionName(this.Transition), true); } } }
//private void OnTransitionCompleted(object sender, EventArgs e) //{ // var clockGroup = sender as ClockGroup; // this.AbortTransition(); // if (clockGroup == null || clockGroup.CurrentState == ClockState.Stopped) // { // this.TransitionCompleted?.Invoke(this, new RoutedEventArgs()); // } //} /// <summary> /// aborts the transaction /// </summary> public void AbortTransition() { // go to normal state and release our hold on the old content. //VisualStateManager.GoToState(this, NormalState, false); IsTransitioning = false; previousContentPresentationSite?.SetValue(ContentPresenter.ContentProperty, null); }
private void ColumnsChanged(object sender, NotifyCollectionChangedEventArgs e) { var columns = sender as IList <DataTableColumn>; int columnNumber; // Column Headings columnNumber = 0; columnHeadings.ColumnDefinitions.Clear(); foreach (var column in columns) { columnHeadings.ColumnDefinitions.Add(new ColumnDefinition() { Width = column.Width }); var columnHeader = new ContentPresenter() { Content = column }; columnHeadings.Children.Add(columnHeader); columnHeader.SetValue(Grid.ColumnProperty, columnNumber); columnNumber++; } // Data data.ItemTemplate = CreateDataItemTemplate(columns); // Summary CreateSummaryFields(columns); CalculateSummary(); summary.ContentTemplate = CreateSummaryTemplate(columns); }
private void Render() { ColumnDefinitions.Clear(); Children.Clear(); if (ItemsSource == null) { return; } var i = 0; foreach (var item in ItemsSource) { var type = item.GetType(); var valueProperty = type.GetProperty(ValueMemberPath); var valueField = type.GetField(ValueMemberPath); var value = valueProperty != null?valueProperty.GetValue(item, null) : valueField != null?valueField.GetValue(item) : 1; var column = new ColumnDefinition { Width = new GridLength(Convert.ToInt64(value), GridUnitType.Star) }; ColumnDefinitions.Add(column); var bar = new ContentPresenter { ContentTemplate = ItemTemplate, Content = item }; Children.Add(bar); bar.SetValue(ColumnProperty, i); i++; } }
private void NodeControl_HeaderMouseDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Released || Keyboard.IsKeyDown(Key.Space)) { return; } NodeControl nodeControl = sender as NodeControl; ContentPresenter contentPresenter = VisualTreeHelper.GetParent(nodeControl) as ContentPresenter; Canvas canvas = VisualTreeHelper.GetParent(contentPresenter) as Canvas; contentPresenter.SetValue(Panel.ZIndexProperty, currentZIndex++); if (!SelectedNodes.Contains(nodeControl.NodeInfo)) { if (Keyboard.IsKeyUp(Key.LeftCtrl) && Keyboard.IsKeyUp(Key.RightCtrl) && Keyboard.IsKeyUp(Key.LeftShift) && Keyboard.IsKeyUp(Key.RightShift)) { SelectedNodes.Clear(); } SelectedNodes.Add(nodeControl.NodeInfo); } movingNodeOrigins = SelectedNodes.Select(n => nodeControls[n]).ToDictionary(n => n, n => movingNodeOrigins.ContainsKey(n) ? movingNodeOrigins[n] : null); movingNodeOffsets = SelectedNodes.Select(n => nodeControls[n]).ToDictionary(n => n, n => movingNodeOffsets.ContainsKey(n) ? movingNodeOffsets[n] : null); foreach (NodeControl n in movingNodeOrigins.Keys.ToArray()) { movingNodeOrigins[n] = new Point(n.NodeInfo.X, n.NodeInfo.Y); movingNodeOffsets[n] = e.GetPosition(n); } }
private void InitializeTick(double i, double j, double middleTickStep, double majorTickStep, DataTemplate tickTemplate, DataTemplate middleTemplate, DataTemplate majorTemplate) { DataTemplate template = tickTemplate; TickType type = TickType.Minor; if (middleTickStep != -1 && j % middleTickStep == 0) { template = middleTemplate; type = TickType.Middle; } if (majorTickStep != -1 && j % majorTickStep == 0) { template = majorTemplate; type = TickType.Major; } ContentPresenter tick = new ContentPresenter(); tick.SetValue(RadGauge.TickTypeProperty, type); InitializeTick(tick, i, template); this.ticks.Add(tick); this.Children.Insert(0, tick); }
private void AddItems(IList items) { foreach (var item in items) { if (Children.Count > 0) { RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); var gridSplitter = new GridSplitter { Height = 5, Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Stretch, }; SetRow(gridSplitter, Children.Count); Children.Add(gridSplitter); } RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star), MinHeight = 40, }); var contentPresenter = new ContentPresenter(); contentPresenter.SetValue(ContentPresenter.ContentTemplateProperty, ItemTemplate); contentPresenter.Content = item; SetRow(contentPresenter, Children.Count); Children.Add(contentPresenter); } }
private static void InitializeTick(ContentPresenter tick, double value, DataTemplate dataTemplate) { tick.ContentTemplate = dataTemplate; tick.SetValue(RadGauge.TickValueProperty, value); // The default value formatter displayes 0d as 0.0000000, that is why we are calling ToString() explicitly tick.Content = value.ToString(CultureInfo.CurrentUICulture.NumberFormat); }
private void SetupSize() { #if !SILVERLIGHT childFontSize = this.FontSize * 16.0 / 21.0; SubscriptView.SetValue(Control.FontSizeProperty, childFontSize); SuperscriptView.SetValue(Control.FontSizeProperty, childFontSize); #endif }
public void Should_Register_With_Host_When_TemplatedParent_Set() { var host = new Mock <IContentPresenterHost>(); var target = new ContentPresenter(); target.SetValue(Control.TemplatedParentProperty, host.Object); host.Verify(x => x.RegisterContentPresenter(target)); }
/// <summary> /// Adds a tick to the bar's visual tree /// </summary> /// <param name="position">The position to place the tick at along the tick bar</param> /// <param name="dataSource">The data to pass to the tick's template</param> private void AddTickmark(double position, object dataSource) { // Create both a minor and major tick mark at the specified position. Layout logic will determine which // one to actually show at the position. // Create a minor tickmark ContentPresenter c = new ContentPresenter() { VerticalAlignment = VerticalAlignment.Top, Content = dataSource }; c.SetValue(PositionProperty, position); c.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding() { Source = this, BindsDirectlyToSource = true, Path = new PropertyPath(nameof(MinorTickmarkTemplate)), }); Children.Add(c); _minorTickmarks.Add(c); // Create a major tickmark c = new ContentPresenter() { VerticalAlignment = VerticalAlignment.Top, Content = dataSource }; c.SetValue(PositionProperty, position); c.SetValue(IsMajorTickmarkProperty, true); c.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding() { Source = this, BindsDirectlyToSource = true, Path = new PropertyPath(nameof(MajorTickmarkTemplate)) }); if (TickLabelFormat != null) { ApplyTickLabelFormat(c, TickLabelFormat); } Children.Add(c); _majorTickmarks.Add(c); }
private void InitializeLabel(double i) { ContentPresenter label = new ContentPresenter(); label.SetValue(RadGauge.TickTypeProperty, TickType.Label); InitializeTick(label, i, this.ownerGauge.LabelTemplate); this.labels.Add(label); this.Children.Insert(0, label); }
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); }
public DragContentAdorner(UIElement adornedElement, object draggedData, DataTemplate dataTemplate, Point offset) : base(adornedElement) { _contentPresenter = new ContentPresenter { Content = draggedData, ContentTemplate = dataTemplate, Opacity = 0.7 }; _translate = new TranslateTransform { X = 0, Y = 0 }; _contentPresenter.RenderTransform = _translate; _offset = offset; Host.Children.Add(_contentPresenter); _contentPresenter.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Left); _contentPresenter.SetValue(VerticalAlignmentProperty, VerticalAlignment.Top); }
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); }
internal void HandleFlyoutStatusChange(Flyout flyout, int visibleFlyouts) { //checks a recently opened flyout's position. if (flyout.Position == Position.Right || flyout.Position == Position.Top) { //get it's zindex var zIndex = flyout.IsOpen ? Panel.GetZIndex(flyout) + 3 : visibleFlyouts + 2; if (this.ShowWindowCommandsOnTop) //if ShowWindowCommandsOnTop is true, set the window commands' zindex to a number that is higher than the flyout's. { WindowCommandsPresenter.SetValue(Panel.ZIndexProperty, zIndex); } WindowButtonCommands.SetValue(Panel.ZIndexProperty, zIndex); } }
FrameworkElement CreateTick(Point start, Point end) { if (TickTemplate == null) { Line ln = new Line(); ln.SetBinding(Line.StrokeProperty, new System.Windows.Data.Binding("Foreground")); ln.StrokeThickness = 1.0; ln.X1 = start.X; ln.Y1 = start.Y; ln.X2 = end.X; ln.Y2 = end.Y; return(ln); } else { ContentPresenter cp = new ContentPresenter(); cp.Content = "a"; cp.ContentTemplate = TickTemplate; cp.SetValue(Canvas.TopProperty, (IsHorizontal ? start.Y : start.Y - cp.ActualHeight / 2)); cp.SetValue(Canvas.LeftProperty, (IsHorizontal ? start.X - cp.ActualWidth / 2 : start.X)); return(cp); } //return null; }
private void SetVisibiltyForTitleBarElements(bool visible) { var value = visible ? Visibility.Visible : Visibility.Collapsed; titleBar?.SetCurrentValue(VisibilityProperty, value); title?.SetCurrentValue(VisibilityProperty, value); SetVisibiltyForIcon(); leftWindowCommands?.SetValue(VisibilityProperty, value); rightWindowCommands?.SetValue(VisibilityProperty, value); windowButtons?.SetCurrentValue(VisibilityProperty, value); SetWindowEvents(); }
protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { Storyboard oldStoryboard = OldContentStoryboard; Storyboard newStoryboard = NewContentStoryboard; if (oldStoryboard != null || newStoryboard != null) { oldContent.Style = OldContentStyle; newContent.Style = NewContentStyle; // Flag to determine when both storyboards are done bool done = oldStoryboard == null || newStoryboard == null; if (oldStoryboard != null) { oldStoryboard = oldStoryboard.Clone(); oldContent.SetValue(OldContentStoryboardProperty, oldStoryboard); oldStoryboard.Completed += delegate { if (done) { EndTransition(transitionElement, oldContent, newContent); } done = true; }; oldStoryboard.Begin(oldContent, true); } if (newStoryboard != null) { newStoryboard = newStoryboard.Clone(); newContent.SetValue(NewContentStoryboardProperty, newStoryboard); newStoryboard.Completed += delegate { if (done) { EndTransition(transitionElement, oldContent, newContent); } done = true; }; newStoryboard.Begin(newContent, true); } } else { EndTransition(transitionElement, oldContent, newContent); } }
internal void HandleFlyoutStatusChange(Flyout flyout, IEnumerable <Flyout> visibleFlyouts) { //checks a recently opened flyout's position. if (flyout.Position == Position.Right || flyout.Position == Position.Top) { //get it's zindex var zIndex = flyout.IsOpen ? Panel.GetZIndex(flyout) + 3 : visibleFlyouts.Count() + 2; if (this.ShowWindowCommandsOnTop) //if ShowWindowCommandsOnTop is true, set the window commands' zindex to a number that is higher than the flyout's. { WindowCommandsPresenter.SetValue(Panel.ZIndexProperty, zIndex); } WindowButtonCommands.SetValue(Panel.ZIndexProperty, zIndex); } flyoutModal.Visibility = visibleFlyouts.Any(x => x.IsModal) ? Visibility.Visible : Visibility.Hidden; }
private void OnLoaded(object sender, RoutedEventArgs e) { if (this.Background == null) { this.Background = new SolidColorBrush(Color.FromRgb(32, 78, 126)); } if (this.BorderBrush == null) { this.BorderBrush = new SolidColorBrush(Color.FromRgb(32, 78, 126)); } if (this.Foreground == null) { this.Foreground = Brushes.White; } if (this.HeaderTemplate == null) { this.CreateHeaderTemplate(); } if (this.ContentTemplate == null) { this.CreateContentTemplate(); } _panel = new DockPanel(); var headerPresenter = new ContentPresenter() { Content = this.Header, ContentTemplate = this.HeaderTemplate }; headerPresenter.SetValue(DockPanel.DockProperty, Dock.Top); _panel.Children.Add(headerPresenter); var contentPresenter = new ContentPresenter() { Content = this.Content, ContentTemplate = this.ContentTemplate }; this.ContentBackground = (this.Content is Control) ? ((Control)this.Content).Background : (this.Content is Panel) ? ((Panel)this.Content).Background : null; _panel.Children.Add(contentPresenter); this.Child = _panel; this.ArrangePopup(); }
private void SetupSize() { #if !SILVERLIGHT var frac = this.Fraction; childFontSize = this.FontSize; if (frac == null) { return; } if (frac.Style == FractionStyle.Slanted) { childFontSize /= 1.5; } else if (frac.Size == FractionSize.Text || (frac.IsSubFraction && frac.Size == FractionSize.Default)) { childFontSize *= 16.0 / 21.0; } NumeratorView.SetValue(Control.FontSizeProperty, childFontSize); DenominatorView.SetValue(Control.FontSizeProperty, childFontSize); #endif }
/// <summary> /// Initializes a new instance of the <see cref="LabeledControlSideRailContainer" /> class. /// </summary> /// <param name="labelText"> /// The label text. "" if you want this control to not be labeled and the contained control to take /// up the entire width of the container /// </param> /// <param name="control">The control.</param> /// <param name="orientation">The orientation.</param> /// <param name="controlSpace"> /// The control space. This sets the controls horizontal or vertical space depending on the /// orientation /// </param> public LabeledControlSideRailContainer(string labelText, Control control, Orientation orientation, double controlSpace) { var desc = DependencyPropertyDescriptor.FromProperty(AdditionalContentProperty, typeof(UserControl)); desc.AddValueChanged(this, ContentPropertyChanged); InitializeComponent(); Label.Content = labelText; AdditionalContent = control; control.HorizontalContentAlignment = HorizontalAlignment.Stretch; if (orientation == Orientation.Horizontal) { if (labelText == string.Empty) { LabelColumn.Width = new GridLength(0); } ControlColumn.Width = labelText == string.Empty ? new GridLength(1, GridUnitType.Auto) : new GridLength(controlSpace); } else { ContentPresenter.SetValue(Grid.RowProperty, 1); ContentPresenter.SetValue(Grid.ColumnProperty, 0); ContentPresenter.SetValue(Grid.ColumnSpanProperty, 2); Label.SetValue(Grid.ColumnSpanProperty, 2); Label.HorizontalContentAlignment = HorizontalAlignment.Center; ControlGrid.Height += controlSpace; } if (orientation == Orientation.Vertical) { control.Height = controlSpace - 4; } control.Margin = new Thickness(2); }
public static void SetCommand(ContentPresenter element, ICommand value) { element.SetValue(CommandProperty, value); }