当前位置: 首页>>代码示例>>C#>>正文


C# Grid.SetBinding方法代码示例

本文整理汇总了C#中System.Windows.Controls.Grid.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.SetBinding方法的具体用法?C# Grid.SetBinding怎么用?C# Grid.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Grid的用法示例。


在下文中一共展示了Grid.SetBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ViewModelExtensions1

 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();
 }
开发者ID:sk8tz,项目名称:DevExpress.Mvvm.Free,代码行数:35,代码来源:ViewHelperTests.cs

示例2: WorkflowItemsPresenter

        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);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:32,代码来源:WorkflowItemsPresenter.cs

示例3: CreateViewModelGrid

        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);
        }
开发者ID:matthijskoopman,项目名称:Catel,代码行数:43,代码来源:ViewModelWrapperService.xaml.cs

示例4: Generate

 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);
     }
 }
开发者ID:Colliotv,项目名称:WMediaPlayer,代码行数:23,代码来源:ChunkView.xaml.cs

示例5: AddPropertyPanel

        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
                                      };
//.........这里部分代码省略.........
开发者ID:yovannyr,项目名称:PropertyTools,代码行数:101,代码来源:PropertyGrid.cs

示例6: CreateViewModelGrid

        /// <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
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:43,代码来源:UserControlLogic.cs

示例7: OnBusyStateChanged

        /// <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);
//.........这里部分代码省略.........
开发者ID:barbarossia,项目名称:CWF,代码行数:101,代码来源:BusyIndicatorBehavior.cs

示例8: InitializeGrid

        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);
        }
开发者ID:adamkrieger,项目名称:CustomControlLibrary_WP8,代码行数:14,代码来源:StrikeableTextBlock.cs

示例9: CreateViewModelGrid

        /// <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");
        }
开发者ID:pars87,项目名称:Catel,代码行数:32,代码来源:UserControlLogic.cs

示例10: PivotPanel

        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;
                    }
                };
        }
开发者ID:gawallsibya,项目名称:BIT_TeamProject,代码行数:45,代码来源:PivotPanel.cs

示例11: ViewLoaded

        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;
                }
            }
        }
开发者ID:nschonni,项目名称:csla-svn,代码行数:84,代码来源:RolodexView.cs

示例12: InitPopup

        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;
        }
开发者ID:kjiwu,项目名称:WP_CustomControls,代码行数:79,代码来源:MyToast.cs

示例13: ShowBrick

        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);
            }
        }
开发者ID:bashocz,项目名称:Examples,代码行数:52,代码来源:Window1.xaml.cs

示例14: CreateLabels

        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;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:72,代码来源:MajorDateTimeLabelProvider.cs

示例15: GenerateUI

        /// <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);
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:101,代码来源:DataField.cs


注:本文中的System.Windows.Controls.Grid.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。