public void ViewModelExtensions1() { var parentVM = new ParentViewModel() { TestParameter = "parameter" }; var childVM = new ChildViewModel(); Grid parentView = new Grid() { DataContext = parentVM }; Grid childView = new Grid() { DataContext = childVM }; childView.SetBinding(ViewModelExtensions.ParameterProperty, new Binding("DataContext.TestParameter") { Source = parentView }); childView.SetBinding(ViewModelExtensions.ParentViewModelProperty, new Binding("DataContext") { Source = parentView }); parentView.Children.Add(childView); Window.Content = parentView; EnqueueShowWindow(); EnqueueCallback(() => { Assert.AreSame(parentVM, ((ISupportParentViewModel)childVM).ParentViewModel); Assert.AreEqual(parentVM.TestParameter, ((ISupportParameter)childVM).Parameter); parentVM.TestParameter = "parameter2"; }); EnqueueWindowUpdateLayout(); EnqueueCallback(() => { Assert.AreSame(parentVM, ((ISupportParentViewModel)childVM).ParentViewModel); Assert.AreEqual(parentVM.TestParameter, ((ISupportParameter)childVM).Parameter); parentVM = new ParentViewModel() { TestParameter = "VM2test" }; parentView.DataContext = parentVM; }); EnqueueWindowUpdateLayout(); EnqueueCallback(() => { Assert.AreSame(parentVM, ((ISupportParentViewModel)childVM).ParentViewModel); Assert.AreEqual(parentVM.TestParameter, ((ISupportParameter)childVM).Parameter); parentVM.TestParameter = "parameter2"; }); EnqueueWindowUpdateLayout(); EnqueueCallback(() => { Assert.AreSame(parentVM, ((ISupportParentViewModel)childVM).ParentViewModel); Assert.AreEqual(parentVM.TestParameter, ((ISupportParameter)childVM).Parameter); }); EnqueueTestComplete(); }
public WorkflowItemsPresenter() { panel = new ItemsControl(); panel.Focusable = false; hintTextGrid = new Grid(); hintTextGrid.Focusable = false; hintTextGrid.Background = Brushes.Transparent; hintTextGrid.DataContext = this; hintTextGrid.SetBinding(Grid.MinHeightProperty, "MinHeight"); hintTextGrid.SetBinding(Grid.MinWidthProperty, "MinWidth"); TextBlock text = new TextBlock(); text.Focusable = false; text.SetBinding(TextBlock.TextProperty, "HintText"); text.HorizontalAlignment = HorizontalAlignment.Center; text.VerticalAlignment = VerticalAlignment.Center; text.DataContext = this; text.Foreground = new SolidColorBrush(SystemColors.GrayTextColor); text.FontStyle = FontStyles.Italic; ((IAddChild)hintTextGrid).AddChild(text); this.outerGrid = new Grid() { RowDefinitions = { new RowDefinition(), new RowDefinition() }, ColumnDefinitions = { new ColumnDefinition() } }; Grid.SetRow(this.panel, 0); Grid.SetColumn(this.panel, 0); Grid.SetRow(this.hintTextGrid, 1); Grid.SetColumn(this.hintTextGrid, 0); this.outerGrid.Children.Add(panel); this.outerGrid.Children.Add(hintTextGrid); }
private IViewModelWrapper CreateViewModelGrid(IView view, object viewModelSource, WrapOptions wrapOptions) { var content = GetContent(view) as FrameworkElement; if (content == null) { return null; } object tempObj = null; if (_weakIsWrappingTable.TryGetValue(view, out tempObj)) { return null; } _weakIsWrappingTable.Add(view, new object()); var vmGrid = new Grid(); vmGrid.Name = InnerWrapperName.GetUniqueControlName(); vmGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath("ViewModel"), Source = viewModelSource }); #if NET || SL5 if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.CreateWarningAndErrorValidatorForViewModel)) { var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); vmGrid.Children.Add(warningAndErrorValidator); } #endif if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.TransferStylesAndTransitionsToViewModelGrid)) { content.TransferStylesAndTransitions(vmGrid); } SetContent(view, null); vmGrid.Children.Add(content); SetContent(view, vmGrid); Log.Debug("Created target control content wrapper grid for view model"); return new ViewModelWrapper(vmGrid); }
internal void Generate() { if (Chunk.Count() <= 6) Container.Rows = 1; else if (Chunk.Count() <= 12) Container.Rows = 2; else if (Chunk.Count() <= 18) Container.Rows = 3; foreach (var picture in Chunk) { Grid grid = new Grid() {Margin = new Thickness(5)}; var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.DecodePixelHeight = 184; bitmap.DecodePixelWidth = 184; bitmap.CreateOptions = BitmapCreateOptions.DelayCreation; bitmap.UriSource = new Uri(picture.Path); bitmap.EndInit(); grid.Children.Add(new Image() { Source = bitmap, Stretch = Stretch.UniformToFill, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center}); grid.SetBinding(Grid.HeightProperty, new Binding("ActualWidth") { Source = grid }); Container.Children.Add(grid); } }
private void AddPropertyPanel(Panel panel, PropertyItem pi, object instance, Tab tab) { // TODO: refactor this method - too long and complex... var propertyPanel = new Grid(); if (!pi.FillTab) { propertyPanel.Margin = new Thickness(2); } var labelColumn = new System.Windows.Controls.ColumnDefinition { Width = GridLength.Auto, MinWidth = this.MinimumLabelWidth, MaxWidth = this.MaximumLabelWidth, SharedSizeGroup = this.LabelWidthSharing != LabelWidthSharing.NotShared ? "labelColumn" : null }; propertyPanel.ColumnDefinitions.Add(labelColumn); propertyPanel.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition()); var rd = new System.Windows.Controls.RowDefinition { Height = pi.FillTab ? new GridLength(1, GridUnitType.Star) : GridLength.Auto }; propertyPanel.RowDefinitions.Add(rd); var propertyLabel = this.CreateLabel(pi); var propertyControl = this.CreatePropertyControl(pi); if (propertyControl != null) { if (!double.IsNaN(pi.Width)) { propertyControl.Width = pi.Width; propertyControl.HorizontalAlignment = HorizontalAlignment.Left; } if (!double.IsNaN(pi.Height)) { propertyControl.Height = pi.Height; } if (!double.IsNaN(pi.MinimumHeight)) { propertyControl.MinHeight = pi.MinimumHeight; } if (!double.IsNaN(pi.MaximumHeight)) { propertyControl.MaxHeight = pi.MaximumHeight; } if (pi.IsOptional) { propertyControl.SetBinding( IsEnabledProperty, pi.OptionalDescriptor != null ? new Binding(pi.OptionalDescriptor.Name) : new Binding(pi.Descriptor.Name) { Converter = NullToBoolConverter }); } if (pi.IsEnabledByRadioButton) { propertyControl.SetBinding( IsEnabledProperty, new Binding(pi.RadioDescriptor.Name) { Converter = new EnumToBooleanConverter() { EnumType = pi.RadioDescriptor.PropertyType }, ConverterParameter = pi.RadioValue }); } var dataErrorInfoInstance = instance as IDataErrorInfo; if (dataErrorInfoInstance != null) { if (this.ValidationTemplate != null) { Validation.SetErrorTemplate(propertyControl, this.ValidationTemplate); } if (this.ValidationErrorStyle != null) { propertyControl.Style = this.ValidationErrorStyle; } var errorControl = new ContentControl { ContentTemplate = this.ValidationErrorTemplate, Focusable = false }; var errorConverter = new DataErrorInfoConverter(dataErrorInfoInstance, pi.PropertyName); var visibilityBinding = new Binding(pi.PropertyName) { Converter = errorConverter, NotifyOnTargetUpdated = true, // ValidatesOnDataErrors = false, #if !NET40 ValidatesOnNotifyDataErrors = false, #endif // ValidatesOnExceptions = false }; errorControl.SetBinding(VisibilityProperty, visibilityBinding); // When the visibility of the error control is changed, updated the HasErrors of the tab errorControl.TargetUpdated += (s, e) => tab.UpdateHasErrors(dataErrorInfoInstance); var contentBinding = new Binding(pi.PropertyName) { Converter = errorConverter, // ValidatesOnDataErrors = false, #if !NET40 ValidatesOnNotifyDataErrors = false, #endif // ValidatesOnExceptions = false }; errorControl.SetBinding(ContentControl.ContentProperty, contentBinding); // Add a row to the panel propertyPanel.RowDefinitions.Add(new System.Windows.Controls.RowDefinition { Height = GridLength.Auto }); propertyPanel.Children.Add(errorControl); Grid.SetRow(errorControl, 1); Grid.SetColumn(errorControl, 1); } Grid.SetColumn(propertyControl, 1); } var actualHeaderPlacement = pi.HeaderPlacement; var checkBoxPropertyControl = propertyControl as CheckBox; if (checkBoxPropertyControl != null) { if (this.CheckBoxLayout != CheckBoxLayout.Header) { checkBoxPropertyControl.Content = propertyLabel; propertyLabel = null; } if (this.CheckBoxLayout == CheckBoxLayout.CollapseHeader) { actualHeaderPlacement = HeaderPlacement.Collapsed; } } switch (actualHeaderPlacement) { case HeaderPlacement.Hidden: break; case HeaderPlacement.Collapsed: { if (propertyControl != null) { Grid.SetColumn(propertyControl, 0); Grid.SetColumnSpan(propertyControl, 2); } break; } default: { // create the label panel var labelPanel = new DockPanel(); if (pi.HeaderPlacement == HeaderPlacement.Left) { DockPanel.SetDock(labelPanel, Dock.Left); } else { // Above if (propertyControl != null) { propertyPanel.RowDefinitions.Add(new System.Windows.Controls.RowDefinition()); Grid.SetColumnSpan(labelPanel, 2); Grid.SetRow(propertyControl, 1); Grid.SetColumn(propertyControl, 0); Grid.SetColumnSpan(propertyControl, 2); } } propertyPanel.Children.Add(labelPanel); if (propertyLabel != null) { DockPanel.SetDock(propertyLabel, Dock.Left); labelPanel.Children.Add(propertyLabel); } if (this.ShowDescriptionIcons && this.DescriptionIcon != null) { if (!string.IsNullOrWhiteSpace(pi.Description)) { var descriptionIconImage = new Image { Source = this.DescriptionIcon, Stretch = Stretch.None, Margin = new Thickness(0, 4, 4, 4), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = this.DescriptionIconAlignment }; // RenderOptions.SetBitmapScalingMode(descriptionIconImage, BitmapScalingMode.NearestNeighbor); labelPanel.Children.Add(descriptionIconImage); if (!string.IsNullOrWhiteSpace(pi.Description)) { descriptionIconImage.ToolTip = this.CreateToolTip(pi.Description); } } } else { labelPanel.ToolTip = this.CreateToolTip(pi.Description); } } break; } // add the property control if (propertyControl != null) { propertyPanel.Children.Add(propertyControl); } // Set the IsEnabled binding of the label if (pi.IsEnabledDescriptor != null && propertyLabel != null) { var isEnabledBinding = new Binding(pi.IsEnabledDescriptor.Name); if (pi.IsEnabledValue != null) { isEnabledBinding.ConverterParameter = pi.IsEnabledValue; isEnabledBinding.Converter = ValueToBooleanConverter; } propertyLabel.SetBinding(IsEnabledProperty, isEnabledBinding); } // Set the IsEnabled binding of the property control if (pi.IsEnabledDescriptor != null && propertyControl != null) { var isEnabledBinding = new Binding(pi.IsEnabledDescriptor.Name); if (pi.IsEnabledValue != null) { isEnabledBinding.ConverterParameter = pi.IsEnabledValue; isEnabledBinding.Converter = ValueToBooleanConverter; } var currentBindingExpression = propertyControl.GetBindingExpression(IsEnabledProperty); if (currentBindingExpression != null) { var multiBinding = new MultiBinding(); multiBinding.Bindings.Add(isEnabledBinding); multiBinding.Bindings.Add(currentBindingExpression.ParentBinding); multiBinding.Converter = AllMultiValueConverter; multiBinding.ConverterParameter = true; propertyControl.SetBinding(IsEnabledProperty, multiBinding); } else { propertyControl.SetBinding(IsEnabledProperty, isEnabledBinding); } } if (pi.IsVisibleDescriptor != null) { propertyPanel.SetBinding( VisibilityProperty, new Binding(pi.IsVisibleDescriptor.Name) { Converter = BoolToVisibilityConverter }); } if (this.EnableLabelWidthResizing && pi.HeaderPlacement == HeaderPlacement.Left) { propertyPanel.Children.Add( new GridSplitter { Width = 4, Background = Brushes.Transparent, HorizontalAlignment = HorizontalAlignment.Right, Focusable = false }); } panel.Children.Add(propertyPanel); }
/// <summary> /// Creates the target control content wrapper grid that contains the view model as a data context. /// </summary> private void CreateViewModelGrid() { var update = new Action(() => { var content = TargetControl.Content as FrameworkElement; if (content == null || ReferenceEquals(content, _viewModelGrid)) { return; } Log.Debug("Creating target control content wrapper grid that will serve as view model container."); _viewModelGrid = new Grid(); _viewModelGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath("ViewModel"), Source = this }); #if NET || SL4 || SL5 if (CreateWarningAndErrorValidatorForViewModel) { var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); _viewModelGrid.Children.Add(warningAndErrorValidator); } #endif TargetControl.Content = null; _viewModelGrid.Children.Add(content); TargetControl.Content = _viewModelGrid; Log.Debug("Created target control content wrapper grid for view model."); }); // NOTE: Beginning invoke (running async) because setting of TargetControl Content property causes memory faults // when this method called by TargetControlContentChanged handler. #if NETFX_CORE TargetControl.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => update()); #else update(); #endif }
/// <summary> /// OnBusyStateChanged /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnBusyStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { bool isBusy = (bool)e.NewValue; bool wasBusy = (bool)e.OldValue; if (isBusy == wasBusy) { return; } var hostGridObject = (GetTargetVisual(d) ?? d); Debug.Assert(hostGridObject != null); var hostGrid = hostGridObject as Grid; if (hostGrid == null) { throw new InvalidCastException( string.Format( "The object being attached to must be of type {0}. Try embedding your visual inside a {0} control, and attaching the behavior to the {0} instead.", typeof(Grid).Name)); } if (isBusy) { Debug.Assert(LogicalTreeHelper.FindLogicalNode(hostGrid, "BusyIndicator") == null); bool dimBackground = GetDimBackground(d); var grid = new Grid { Name = "BusyIndicator", Opacity = 0.0 }; if (dimBackground) { grid.Cursor = Cursors.Wait; grid.ForceCursor = true; InputManager.Current.PreProcessInput += OnPreProcessInput; } grid.SetBinding(FrameworkElement.WidthProperty, new Binding("ActualWidth") { Source = hostGrid }); grid.SetBinding(FrameworkElement.HeightProperty, new Binding("ActualHeight") { Source = hostGrid }); for (int i = 1; i <= 3; ++i) { grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); } ProgressIndicator = new BusyIndicator() { Width = 150, Height = 120 }; var viewbox = new Viewbox { HorizontalAlignment = HorizontalAlignment.Center, Stretch = Stretch.Uniform, StretchDirection = StretchDirection.Both, Child = ProgressIndicator }; grid.SetValue(Panel.ZIndexProperty, 1000); grid.SetValue(Grid.RowSpanProperty, Math.Max(1, hostGrid.RowDefinitions.Count)); grid.SetValue(Grid.ColumnSpanProperty, Math.Max(1, hostGrid.ColumnDefinitions.Count)); if (GetAddMargins(d)) { viewbox.SetValue(Grid.RowProperty, 1); viewbox.SetValue(Grid.ColumnProperty, 1); } else { viewbox.SetValue(Grid.RowSpanProperty, 3); viewbox.SetValue(Grid.ColumnSpanProperty, 3); } viewbox.SetValue(Panel.ZIndexProperty, 1); var dimmer = new Rectangle { Name = "Dimmer", Opacity = GetDimmerOpacity(d), Fill = GetDimmerBrush(d), Visibility = (dimBackground ? Visibility.Visible : Visibility.Collapsed) }; dimmer.SetValue(Grid.RowSpanProperty, 3); dimmer.SetValue(Grid.ColumnSpanProperty, 3); dimmer.SetValue(Panel.ZIndexProperty, 0); grid.Children.Add(dimmer); grid.Children.Add(viewbox); grid.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(1.0, GetDimTransitionDuration(d))); hostGrid.Children.Add(grid); } else { var grid = (Grid)LogicalTreeHelper.FindLogicalNode(hostGrid, "BusyIndicator"); Debug.Assert(grid != null); if (grid != null) { grid.Name = string.Empty; var fadeOutAnimation = new DoubleAnimation(0.0, GetDimTransitionDuration(d)); fadeOutAnimation.Completed += (sender, args) => OnFadeOutAnimationCompleted(d, hostGrid, grid); grid.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation); } } }
private void InitializeGrid() { _grid = new Grid(); _grid.AddAutoHeightRow(); _grid.AddAutoWidthColumn(); var backgroundBinding = new Binding { Source = this, Path = new PropertyPath("Background") }; _grid.SetBinding(Grid.BackgroundProperty, backgroundBinding); }
/// <summary> /// Creates the grid that contains the view model as a data context. /// </summary> private void CreateViewModelGrid() { var content = TargetControl.Content as FrameworkElement; if (content == null) { return; } Log.Debug("Creating view model grid that will serve as view model container"); _viewModelGrid = new Grid(); _viewModelGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath("ViewModel"), Source = this }); #if NET || SL4 || SL5 if (CreateWarningAndErrorValidatorForViewModel) { var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); _viewModelGrid.Children.Add(warningAndErrorValidator); } #endif TargetControl.Content = null; _viewModelGrid.Children.Add(content); TargetControl.Content = _viewModelGrid; Log.Debug("Created view model grid"); }
public PivotPanel() { notifiableChildren = new NotifiableUIElementCollection(this, this); // Create the root grid that will hold the header panel and the contents rootGrid = new Grid(); RowDefinition rd = new RowDefinition(); rd.Height = HeaderHeight; rootGrid.RowDefinitions.Add(rd); rd = new RowDefinition(); rd.Height = new GridLength(1, GridUnitType.Star); rootGrid.RowDefinitions.Add(rd); Binding backgroundBinding = new Binding(); backgroundBinding.Source = this.Background; rootGrid.SetBinding(Grid.BackgroundProperty, backgroundBinding); rootGrid.Width = this.ActualWidth; rootGrid.Height = this.ActualHeight; rootGrid.HorizontalAlignment = HorizontalAlignment.Stretch; rootGrid.VerticalAlignment = VerticalAlignment.Stretch; // Create the header panel headerPanel = new PivotHeaderPanel(); headerPanel.HorizontalAlignment = HorizontalAlignment.Stretch; headerPanel.VerticalAlignment = VerticalAlignment.Stretch; headerPanel.HeaderSelected += new EventHandler(OnHeaderSelected); rootGrid.Children.Add(headerPanel); this.Children.Add(rootGrid); pivotItems = new List<PivotItem>(); this.SizeChanged += (s, e) => { if (rootGrid != null) { rootGrid.Width = this.ActualWidth; rootGrid.Height = this.ActualHeight; } }; }
private void ViewLoaded(object sender, RoutedEventArgs e) { if (DataContext is IRolodexViewModel) { var model = DataContext as IRolodexViewModel; Grid root = null; if (Content is Grid) { root = Content as Grid; } else if (Content is Border) { if ((Content as Border).Child is Grid) { root = (Content as Border).Child as Grid; } } if (root != null) { if (root.Background == null) { root.Background = new SolidColorBrush(Colors.LightGray); } var curtainGrid = new Grid(); curtainGrid.SetValue(Canvas.ZIndexProperty, 9999); curtainGrid.Opacity = 0.6; curtainGrid.SetValue(Grid.RowSpanProperty, root.RowDefinitions.Count + 1); curtainGrid.SetValue(Grid.ColumnSpanProperty, root.ColumnDefinitions.Count + 1); var brush = new LinearGradientBrush {EndPoint = new Point(0.5, 1), StartPoint = new Point(0.5, 0)}; var stops = new GradientStopCollection(); var stop = new GradientStop {Color = new Color {R = 0x80, G = 0x74, B = 0xD4}}; stops.Add(stop); stop = new GradientStop {Color = new Color {R = 0x80, G = 0x74, B = 0xD4}, Offset = 1}; stops.Add(stop); stop = new GradientStop {Color = new Color {R = 0xB7, G = 0x84, B = 0xD0}, Offset = 0.5}; stops.Add(stop); brush.GradientStops = stops; curtainGrid.Background = brush; var busyAnimation = new BusyAnimation { MinHeight = 48, MinWidth = 48, MaxHeight = 300, MaxWidth = 300, TabNavigation = System.Windows.Input.KeyboardNavigationMode.Cycle }; var binding = new Binding("IsBusy"); busyAnimation.HorizontalAlignment = HorizontalAlignment.Stretch; busyAnimation.VerticalAlignment = VerticalAlignment.Stretch; busyAnimation.SetBinding(BusyAnimation.IsRunningProperty, binding); curtainGrid.Children.Add(busyAnimation); binding = new Binding("IsBusy") {Converter = new BooleanToVisibilityConverter()}; curtainGrid.SetBinding(VisibilityProperty, binding); root.Children.Add(curtainGrid); if (model.IsBusy) { Dispatcher.BeginInvoke(() => busyAnimation.Focus()); } model.PropertyChanged += (o1, e1) => { if (e1.PropertyName == "IsBusy") { if (model.IsBusy) busyAnimation.Focus(); else Focus(); } }; Loaded -= ViewLoaded; } } }
private void InitPopup() { Binding fontSizeBinding = new Binding("FontSize"); fontSizeBinding.Source = this; Binding fontWeightBinding = new Binding("FontWeight"); fontWeightBinding.Source = this; Binding foregroundBinding = new Binding("Foreground"); foregroundBinding.Source = this; popup = new Popup(); popup.VerticalOffset = SystemTray.IsVisible ? 30 : 0; Grid grid = new Grid(); grid.MinHeight = MinHeight; grid.Width = Application.Current.Host.Content.ActualWidth; PlaneProjection projection = new PlaneProjection() { RotationX = -90 }; grid.Projection = projection; Binding backBinding = new Binding("Background"); backBinding.Source = this; grid.SetBinding(Grid.BackgroundProperty, backBinding); ColumnDefinition col1 = new ColumnDefinition() { Width = GridLength.Auto }; ColumnDefinition col2 = new ColumnDefinition() { Width = GridLength.Auto }; ColumnDefinition col3 = new ColumnDefinition(); grid.ColumnDefinitions.Add(col1); grid.ColumnDefinitions.Add(col2); grid.ColumnDefinitions.Add(col3); Image imgIcon = new Image(); imgIcon.Margin = new Thickness(4); Binding imgBinding = new Binding("Icon"); imgBinding.Source = this; var imageMaxWidthBinding = new Binding("MinHeight"); imageMaxWidthBinding.Source = this; imgIcon.SetBinding(Image.MaxWidthProperty, imageMaxWidthBinding); imgIcon.Stretch = Stretch.Fill; imgIcon.SetBinding(Image.SourceProperty, imgBinding); grid.Children.Add(imgIcon); TextBlock tbkTitle = new TextBlock(); tbkTitle.VerticalAlignment = System.Windows.VerticalAlignment.Center; tbkTitle.Margin = new Thickness(4); Binding titleBinding = new Binding("Title"); titleBinding.Source = this; tbkTitle.SetBinding(TextBlock.TextProperty, titleBinding); tbkTitle.SetBinding(TextBlock.FontSizeProperty, fontSizeBinding); tbkTitle.SetBinding(TextBlock.FontWeightProperty, fontWeightBinding); tbkTitle.SetBinding(TextBlock.ForegroundProperty, foregroundBinding); tbkTitle.SetValue(Grid.ColumnProperty, 1); grid.Children.Add(tbkTitle); TextBlock tbkContent = new TextBlock(); tbkContent.VerticalAlignment = System.Windows.VerticalAlignment.Center; tbkContent.Margin = new Thickness(4); Binding contentBinding = new Binding("Content"); contentBinding.Source = this; tbkContent.SetBinding(TextBlock.TextProperty, contentBinding); tbkContent.SetBinding(TextBlock.FontSizeProperty, fontSizeBinding); tbkContent.SetBinding(TextBlock.FontWeightProperty, fontWeightBinding); tbkContent.SetBinding(TextBlock.ForegroundProperty, foregroundBinding); tbkContent.SetValue(Grid.ColumnProperty, 2); grid.Children.Add(tbkContent); popup.Child = grid; }
private void ShowBrick(StackPanel panel, List<Brick> bricks) { panel.Children.Clear(); int brickIndex = 0; List<Grid> grids = new List<Grid>(); foreach (Brick brick in bricks) { brickIndex++; while (grids.Count < (brick.Row + 1)) { Grid grid = new Grid(); for (int idx = 0; idx < 4; idx++) grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.Height = 50; grid.Background = new SolidColorBrush(Colors.Lime); MultiBinding multiBinding = new MultiBinding(); multiBinding.Converter = new BrickVisibleConverter(); multiBinding.ConverterParameter = grids.Count + 1; Binding binding = new Binding(); binding.Source = panel; binding.Path = new PropertyPath(FrameworkElement.ActualHeightProperty); multiBinding.Bindings.Add(binding); binding = new Binding(); binding.Source = grid; binding.Path = new PropertyPath(FrameworkElement.ActualHeightProperty); multiBinding.Bindings.Add(binding); grid.SetBinding(Grid.VisibilityProperty, multiBinding); grids.Add(grid); panel.Children.Add(grid); } Border border = new Border(); border.Background = new SolidColorBrush(Colors.Blue); border.Margin = new Thickness(5); Grid.SetColumn(border, brick.Column); Grid.SetColumnSpan(border, brick.Span); TextBlock text = new TextBlock(); text.Text = brickIndex.ToString(); border.Child = text; grids[brick.Row].Children.Add(border); } }
public override UIElement[] CreateLabels(ITicksInfo<DateTime> ticksInfo) { object info = ticksInfo.Info; var ticks = ticksInfo.Ticks; UIElement[] res = new UIElement[ticks.Length - 1]; int labelsNum = 3; if (info is DifferenceIn) { DifferenceIn diff = (DifferenceIn)info; DateFormat = GetDateFormat(diff); } else if (info is MajorLabelsInfo) { MajorLabelsInfo mInfo = (MajorLabelsInfo)info; DifferenceIn diff = (DifferenceIn)mInfo.Info; DateFormat = GetDateFormat(diff); labelsNum = mInfo.MajorLabelsCount + 1; //DebugVerify.Is(labelsNum < 100); } DebugVerify.Is(ticks.Length < 10); LabelTickInfo<DateTime> tickInfo = new LabelTickInfo<DateTime>(); for (int i = 0; i < ticks.Length - 1; i++) { tickInfo.Info = info; tickInfo.Tick = ticks[i]; string tickText = GetString(tickInfo); Grid grid = new Grid { }; // doing binding as described at http://sdolha.spaces.live.com/blog/cns!4121802308C5AB4E!3724.entry?wa=wsignin1.0&sa=835372863 grid.SetBinding(Grid.BackgroundProperty, new Binding { Path = new PropertyPath("(0)", DateTimeAxis.MajorLabelBackgroundBrushProperty), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(AxisControlBase) } }); Rectangle rect = new Rectangle { StrokeThickness = 2 }; rect.SetBinding(Rectangle.StrokeProperty, new Binding { Path = new PropertyPath("(0)", DateTimeAxis.MajorLabelRectangleBorderPropertyProperty), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(AxisControlBase) } }); Grid.SetColumn(rect, 0); Grid.SetColumnSpan(rect, labelsNum); for (int j = 0; j < labelsNum; j++) { grid.ColumnDefinitions.Add(new ColumnDefinition()); } grid.Children.Add(rect); for (int j = 0; j < labelsNum; j++) { var tb = new TextBlock { Text = tickText, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 3, 0, 3) }; Grid.SetColumn(tb, j); grid.Children.Add(tb); } ApplyCustomView(tickInfo, grid); res[i] = grid; } return res; }
/// <summary> /// Generates the UI for this field. /// </summary> private void GenerateUI() { if (this._contentControl == null) { return; } this._boundProperty = null; Grid grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }); this.LabelColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; grid.ColumnDefinitions.Add(this.LabelColumn); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(FieldElementSpacing, GridUnitType.Pixel) }); // Content column: grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(FieldElementSpacing, GridUnitType.Pixel) }); this.DescriptionColumnBesideContent = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; grid.ColumnDefinitions.Add(this.DescriptionColumnBesideContent); Grid labelGrid = new Grid(); this.InternalLabel = new Label(); this.InternalLabel.SetBinding(System.Windows.Controls.Label.PropertyPathProperty, new Binding("PropertyPath") { Source = this }); this.InternalLabel.SetBinding(System.Windows.Controls.Label.VisibilityProperty, new Binding("LabelVisibility") { Source = this }); this.SetLabelContent(); this.SetIsReadOnlyIfNotOverridden(); this.SetIsRequiredIfNotOverridden(); labelGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); labelGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); this.DescriptionColumnBesideLabelSeparator = new ColumnDefinition() { Width = new GridLength(0, GridUnitType.Pixel) }; labelGrid.ColumnDefinitions.Add(this.DescriptionColumnBesideLabelSeparator); this.DescriptionColumnBesideLabel = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; labelGrid.ColumnDefinitions.Add(this.DescriptionColumnBesideLabel); if (this._isRequiredOverridden) { this.InternalLabel.IsRequired = this.IsRequired; } else if (this.EffectiveMode == DataFieldMode.ReadOnly) { this.InternalLabel.IsRequired = false; } Panel oldPanel = VisualTreeHelper.GetParent(this.InternalLabel) as Panel; if (oldPanel != null) { oldPanel.Children.Remove(this.InternalLabel); } labelGrid.Children.Add(this.InternalLabel); if (this.EffectiveLabelPosition == DataFieldLabelPosition.Top) { Grid.SetRow(labelGrid, 0); Grid.SetColumn(labelGrid, 2); } else { Grid.SetRow(labelGrid, 1); Grid.SetColumn(labelGrid, 0); } // Make the label grid have the same horizontal alignment as the label. labelGrid.SetBinding(FrameworkElement.HorizontalAlignmentProperty, new Binding("HorizontalAlignment") { Source = this.InternalLabel }); grid.Children.Add(labelGrid); this.InternalLabel.MouseLeftButtonDown += new MouseButtonEventHandler(this.OnLabelMouseLeftButtonDown); this.InternalLabel.SizeChanged += new SizeChangedEventHandler(this.OnLabelSizeChanged); if (this.Content != null) { if (this.IsReadOnly) { this.SetContentReadOnlyState(true /* isReadOnly */); } else { this.SetContentReadOnlyState(false /* isReadOnly */); } this.Content.Loaded -= new RoutedEventHandler(this.OnContentLoaded); this.Content.Loaded += new RoutedEventHandler(this.OnContentLoaded); oldPanel = VisualTreeHelper.GetParent(this.Content) as Panel; if (oldPanel != null) { oldPanel.Children.Remove(this.Content); } grid.Children.Add(this.Content); Grid.SetRow(this.Content, 1); Grid.SetColumn(this.Content, 2); } this.DescriptionViewer = new DescriptionViewer(); this.DescriptionViewer.SetBinding(DescriptionViewer.PropertyPathProperty, new Binding("PropertyPath") { Source = this }); this.DescriptionViewer.SetBinding(DescriptionViewer.VisibilityProperty, new Binding("DescriptionViewerVisibility") { Source = this }); this.SetDescriptionContent(); oldPanel = VisualTreeHelper.GetParent(this.DescriptionViewer) as Panel; if (oldPanel != null) { oldPanel.Children.Remove(this.DescriptionViewer); } if (this.EffectiveDescriptionViewerPosition == DataFieldDescriptionViewerPosition.BesideLabel) { this.DescriptionColumnBesideLabelSeparator.Width = new GridLength(FieldElementSpacing, GridUnitType.Pixel); Grid.SetColumn(this.DescriptionViewer, 2); labelGrid.Children.Add(this.DescriptionViewer); } else { Grid.SetRow(this.DescriptionViewer, 1); Grid.SetColumn(this.DescriptionViewer, 4); grid.Children.Add(this.DescriptionViewer); } this.DescriptionViewer.SizeChanged += new SizeChangedEventHandler(this.OnDescriptionSizeChanged); // Don't display the description when in read-only mode. if (this.IsReadOnly) { this.DescriptionViewer.Opacity = 0; this.DescriptionViewer.IsHitTestVisible = false; } this.RemoveLabelColumnAlignment(); this.RemoveDescriptionColumnAlignment(); this._contentControl.Content = grid; }
private void InitPopup() { popup = new Popup(); popup.Opened += popup_Opened; Binding backgroundBinding = new Binding("Background"); backgroundBinding.Source = this; Binding foregroundBinding = new Binding("Foreground"); foregroundBinding.Source = this; Grid border = new Grid(); border.Background = new SolidColorBrush(Color.FromArgb(200, 0, 0, 0)); border.Width = Application.Current.Host.Content.ActualWidth; border.Height = Application.Current.Host.Content.ActualHeight; Grid container = new Grid(); CompositeTransform transform = new CompositeTransform() { TranslateY = -Application.Current.Host.Content.ActualHeight }; container.RenderTransform = transform; container.VerticalAlignment = System.Windows.VerticalAlignment.Top; container.SetBinding(Grid.BackgroundProperty, backgroundBinding); #region init grid rows RowDefinition row1 = new RowDefinition() { Height = GridLength.Auto }; container.RowDefinitions.Add(row1); RowDefinition row2 = new RowDefinition() { Height = GridLength.Auto }; container.RowDefinitions.Add(row2); RowDefinition row3 = new RowDefinition() { Height = GridLength.Auto }; container.RowDefinitions.Add(row3); #endregion TextBlock title = new TextBlock() { Margin = new Thickness(12), FontSize = 30, FontWeight = FontWeights.Black }; Binding titleBinding = new Binding("Title"); titleBinding.Source = this; title.SetBinding(TextBlock.TextProperty, titleBinding); title.SetBinding(TextBlock.ForegroundProperty, foregroundBinding); container.Children.Add(title); TextBlock content = new TextBlock() { Margin = new Thickness(12), FontSize = 26, FontWeight = FontWeights.Medium }; Binding contentBinding = new Binding("Content"); contentBinding.Source = this; content.SetBinding(TextBlock.TextProperty, contentBinding); content.SetBinding(TextBlock.ForegroundProperty, foregroundBinding); content.SetValue(Grid.RowProperty, 1); container.Children.Add(content); switch (MessageBoxButtons) { case MessageBoxButton.OK: { Button btn = new Button() { Content = "OK", Margin = new Thickness(0, 0, 0, 10) }; btn.Click += (s, args) => { var handler = OKClick; if (null != handler) { handler(this, new RoutedEventArgs()); } GetCloseAnimation(); }; btn.SetValue(Grid.RowProperty, 2); container.Children.Add(btn); } break; case MessageBoxButton.OKCancel: { Grid btnGrid = new Grid(); btnGrid.Margin = new Thickness(0, 0, 0, 10); btnGrid.SetValue(Grid.RowProperty, 2); ColumnDefinition column1 = new ColumnDefinition(); ColumnDefinition column2 = new ColumnDefinition(); btnGrid.ColumnDefinitions.Add(column1); btnGrid.ColumnDefinitions.Add(column2); Button btnOK = new Button() { Content = "OK" }; btnOK.Click += (s, args) => { var handler = OKClick; if (null != handler) { handler(this, new RoutedEventArgs()); } GetCloseAnimation(); }; btnGrid.Children.Add(btnOK); Button btnCancel = new Button() { Content = "Cancel" }; btnCancel.Click += (s, args) => { var handler = CancelClick; if (null != handler) { handler(this, new RoutedEventArgs()); } GetCloseAnimation(); }; btnCancel.SetValue(Grid.ColumnProperty, 1); btnGrid.Children.Add(btnCancel); container.Children.Add(btnGrid); } break; } border.Children.Add(container); popup.Child = border; }
void CreateInternalGrid() { _internalGrid = new Grid() { FlowDirection = System.Windows.FlowDirection.LeftToRight}; _internalGrid.SetBinding(Grid.BackgroundProperty, new Binding("Background") { Source = this }); _internalHost = new LayoutAnchorableControl() { Model = _model, Style = AnchorableStyle }; _internalHost.SetBinding(FlowDirectionProperty, new Binding("Model.Root.Manager.FlowDirection") { Source = this }); KeyboardNavigation.SetTabNavigation(_internalGrid, KeyboardNavigationMode.Cycle); _resizer = new LayoutGridResizerControl(); _resizer.DragStarted += new System.Windows.Controls.Primitives.DragStartedEventHandler(OnResizerDragStarted); _resizer.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(OnResizerDragDelta); _resizer.DragCompleted += new System.Windows.Controls.Primitives.DragCompletedEventHandler(OnResizerDragCompleted); if (_side == AnchorSide.Right) { _internalGrid.ColumnDefinitions.Add(new ColumnDefinition(){ Width = new GridLength(_manager.GridSplitterWidth)}); _internalGrid.ColumnDefinitions.Add(new ColumnDefinition(){ Width = _model.AutoHideWidth == 0.0 ? new GridLength(_model.AutoHideMinWidth) : new GridLength(_model.AutoHideWidth, GridUnitType.Pixel)}); Grid.SetColumn(_resizer, 0); Grid.SetColumn(_internalHost, 1); _resizer.Cursor = Cursors.SizeWE; HorizontalAlignment = System.Windows.HorizontalAlignment.Right; VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else if (_side == AnchorSide.Left) { _internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = _model.AutoHideWidth == 0.0 ? new GridLength(_model.AutoHideMinWidth) : new GridLength(_model.AutoHideWidth, GridUnitType.Pixel), }); _internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(_manager.GridSplitterWidth) }); Grid.SetColumn(_internalHost, 0); Grid.SetColumn(_resizer, 1); _resizer.Cursor = Cursors.SizeWE; HorizontalAlignment = System.Windows.HorizontalAlignment.Left; VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else if (_side == AnchorSide.Top) { _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = _model.AutoHideHeight == 0.0 ? new GridLength(_model.AutoHideMinHeight) : new GridLength(_model.AutoHideHeight, GridUnitType.Pixel), }); _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(_manager.GridSplitterHeight) }); Grid.SetRow(_internalHost, 0); Grid.SetRow(_resizer, 1); _resizer.Cursor = Cursors.SizeNS; VerticalAlignment = System.Windows.VerticalAlignment.Top; HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } else if (_side == AnchorSide.Bottom) { _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(_manager.GridSplitterHeight) }); _internalGrid.RowDefinitions.Add(new RowDefinition() { Height = _model.AutoHideHeight == 0.0 ? new GridLength(_model.AutoHideMinHeight) : new GridLength(_model.AutoHideHeight, GridUnitType.Pixel), }); Grid.SetRow(_resizer, 0); Grid.SetRow(_internalHost, 1); _resizer.Cursor = Cursors.SizeNS; VerticalAlignment = System.Windows.VerticalAlignment.Bottom; HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } _internalGrid.Children.Add(_resizer); _internalGrid.Children.Add(_internalHost); _internalHostPresenter.Content = _internalGrid; }
public PivotPanel() { NotifiableChildren = new NotifiableUIElementCollection(this, this); // Create the root grid that will hold the header panel and the contents _rootGrid = new Grid(); RowDefinition rd = new RowDefinition { Height = HeaderHeight }; _rootGrid.RowDefinitions.Add(rd); rd = new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }; _rootGrid.RowDefinitions.Add(rd); Binding backgroundBinding = new Binding { Source = Background }; _rootGrid.SetBinding(BackgroundProperty, backgroundBinding); _rootGrid.Width = ActualWidth; _rootGrid.Height = ActualHeight; _rootGrid.HorizontalAlignment = HorizontalAlignment.Stretch; _rootGrid.VerticalAlignment = VerticalAlignment.Stretch; // Create the header panel _headerPanel = new PivotHeaderPanel { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; _headerPanel.HeaderSelected += OnHeaderSelected; _rootGrid.Children.Add(_headerPanel); Children.Add(_rootGrid); _pivotItems = new List<PivotItem>(); SizeChanged += (s, e) => { if (_rootGrid != null) { _rootGrid.Width = ActualWidth; _rootGrid.Height = ActualHeight; } }; }