public PageBuilder(double width, double height, int marginsLeft, int marginsTop, int marginsRight, int marginsBottom, ContentControl frame)
        {
            _page = new PageContent();
              _fixedPage = new FixedPage {Background = Brushes.White, Width = width, Height = height};

              _repeater = new Repeater();
              var repeatContainer = new Grid {Margin = new Thickness(marginsLeft, marginsTop, marginsRight, marginsBottom)};
              repeatContainer.Children.Add(_repeater);

              frame.SetValue(FixedPage.LeftProperty, 0.00);
              frame.SetValue(FixedPage.TopProperty, 0.00);
              frame.SetValue(FrameworkElement.WidthProperty, _fixedPage.Width);
              frame.SetValue(FrameworkElement.HeightProperty, _fixedPage.Height);

              _fixedPage.Children.Add(frame);
              ((IAddChild)_page).AddChild(_fixedPage);

              frame.Content = repeatContainer;

              frame.Measure(new Size(width, height));
              frame.Arrange(new Rect(0, 0, width, height));

              _repeater.Width = repeatContainer.ActualWidth;
              _repeater.Height = repeatContainer.ActualHeight;
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            double widthOfArrowElement = 12;
            double widthOfLabelText = Width;
            if (DisplayArrowBesideText)
                widthOfLabelText = (!double.IsNaN(Width) ? (Width - widthOfArrowElement - 4) : 32);


            SplitElementContainerGrid = GetTemplateChild(PART_SplitElementContainerGrid) as Grid;
            if (SplitElementContainerGrid != null)
            {
                if (DisplayArrowBesideText)
                {
                    SplitElementContainerGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(widthOfLabelText) });
                    SplitElementContainerGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(widthOfArrowElement) });
                }
                else
                {
                    SplitElementContainerGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0, GridUnitType.Auto) });
                    SplitElementContainerGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0, GridUnitType.Auto) });
                }
            }

            LabelTextElement = GetTemplateChild(PART_LabelTextElement) as TextBlock;
            if (LabelTextElement != null)
            {
                if (DisplayArrowBesideText)
                    LabelTextElement.Width = widthOfLabelText;
                else
                    LabelTextElement.Width = Width;
            }

            ArrowElement = GetTemplateChild(PART_ArrowElement) as ContentControl;
            if (ArrowElement != null)
            {
                if (DisplayArrowBesideText)
                {
                    ArrowElement.Width = widthOfArrowElement;
                    ArrowElement.SetValue(Grid.ColumnProperty, 1);
                    ArrowElement.Margin = new Thickness(0, 5, 5, 0);
                }
                else
                {
                    ArrowElement.Width = Width;
                    ArrowElement.SetValue(Grid.RowProperty, 1);
                }
            }
        }
 internal void AddAdditionalContent(PrintContent content)
 {
     var holder = new ContentControl { Content = content.Visual };
     holder.SetValue(DockPanel.DockProperty, content.Position);
     dockPanel.Children.Insert(0, holder);
     _holders.Add(holder);
 }
Example #4
0
        private static SingleViewBehavior GetOrCreateBehavior(ContentControl control)
        {
            SingleViewBehavior behavior = control.GetValue(SingleViewBehaviorProperty) as SingleViewBehavior;
            if (behavior == null)
            {
                behavior = new SingleViewBehavior(control);
                control.SetValue(SingleViewBehaviorProperty, behavior);
            }

            return behavior;
        }
Example #5
0
File: Test.cs Project: dfr0/moon
		void RunTest ()
		{
			// Store a CLR object in a custom DP. Make that CLR object hold
			// a reference to the Control its stored in to try and create a
			// cycle which prevents GC.
			var dp = DependencyProperty.RegisterAttached ("CustomGCCheckDP", typeof (Wrapper), typeof (ContentControl), null);
			WeakControl = new ContentControl ();
			WeakControl.SetValue (dp, new Wrapper { Value = WeakControl });
			
			GCAndInvoke (() => {
				if (WeakControl == null)
					Succeed ();
				else
					Fail ("FailureReason");
			});
		}
 private void UpdateLog()
 {
     if (Log == null) { return; }
     var rowCount = 0;
     foreach (var entry in Log.Entries)
     {
         var content = new ContentControl
         {
             HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
             VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
             ContentTemplate = FindResource("TimeEntryTemplate") as DataTemplate,
             Content = entry
         };
         content.SetValue(Grid.RowProperty, rowCount);
         TimeEntriesGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
         TimeEntriesGrid.Children.Add(content);
         rowCount++;
     }
 }
        private void GenerateField(string fieldName, Grid grid, BindingMode bindingMode)
        {
            int gridRow = grid.RowDefinitions.Count;
            grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });

            ContentControl fieldLabel = new ContentControl();
            if (this.LabelStyle != null)
            {
                fieldLabel.Style = this.LabelStyle;
            }
            else
            {
                fieldLabel.Content = fieldName;
            }

            fieldLabel.VerticalAlignment = VerticalAlignment.Center;
            if (this.LabelPosition == FeatureDataFormLabelPosition.Top)
            {
                fieldLabel.HorizontalAlignment = HorizontalAlignment.Left;
            }
            else
            {
                fieldLabel.HorizontalAlignment = HorizontalAlignment.Right;
            }

            fieldLabel.DataContext = fieldName;
            fieldLabel.SetValue(Grid.RowProperty, gridRow);
            if (this.LabelPosition == FeatureDataFormLabelPosition.Top)
            {
                fieldLabel.SetValue(Grid.ColumnProperty, 1);
                grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
                gridRow++;
            }
            else
            {
                fieldLabel.SetValue(Grid.ColumnProperty, 0);
            }
            grid.Children.Add(fieldLabel);

            object typeIdFieldValue = (fieldName != null && this.FeatureSource.Attributes.ContainsKey(fieldName)) ? this.FeatureSource.Attributes[fieldName] : null;
            PopulateFieldControl(fieldName, grid, bindingMode, gridRow);
        }
Example #8
0
 public static void SetViewType(ContentControl control, string viewType)
 {
     control.SetValue(ViewTypeProperty, viewType);
 }
        /// <summary>
        /// This method constructs the document page (visual) to print
        /// </summary>
        private DocumentPage ConstructPage(Grid content, int pageNumber)
        {
            if (content == null)
                return null;

            //Build the page inc header and footer
            var pageGrid = new Grid();
            pageGrid.FlowDirection = FlowDirection.RightToLeft;

            //Header row
            AddGridRow(pageGrid, GridLength.Auto);

            //Content row
            AddGridRow(pageGrid, new GridLength(1.0d, GridUnitType.Star));

            //Footer row
            AddGridRow(pageGrid, GridLength.Auto);

            var pageHeader = new ContentControl {Content = CreateDocumentHeader()};
            pageGrid.Children.Add(pageHeader);

            content.SetValue(Grid.RowProperty, 1);
            pageGrid.Children.Add(content);

            var pageFooter = new ContentControl {Content = CreateDocumentFooter(pageNumber + 1)};
            pageFooter.SetValue(Grid.RowProperty, 2);

            pageGrid.Children.Add(pageFooter);

            double width = PageSize.Width - (PageMargin.Left + PageMargin.Right);
            double height = PageSize.Height - (PageMargin.Top + PageMargin.Bottom);

            pageGrid.Measure(new Size(width, height));
            pageGrid.Arrange(new Rect(PageMargin.Left, PageMargin.Top, width, height));

            return new DocumentPage(pageGrid);
        }
        public void OpenPopup(bool UseMouse)
        {
            root = FindWindow(this);
            isMouseMode = UseMouse;
            if (root == null)
                return;
            this.Visibility = Visibility.Collapsed;
            overlay = new Canvas();
            RenderTargetBitmap content = new RenderTargetBitmap((int)root.ActualWidth, (int)root.ActualHeight, 96, 96, PixelFormats.Pbgra32);
            content.Render(root);
            _contentLayer = new Image() { Source = content, Width = root.ActualWidth, Height = root.ActualHeight };
            overlay.Children.Add(_contentLayer);
            overlay.Width = root.ActualWidth;
            overlay.Height = root.ActualHeight;

            mask.Opacity = 0;
            mask.Width = root.ActualWidth;
            mask.Height = root.ActualHeight;
            overlay.Children.Add(mask);

            myContent = this.Content as FrameworkElement;
            myContentSize = new Size(myContent.ActualWidth, myContent.ActualHeight);
            this.Content = null;
            selfLayer = new ContentControl() { Content = myContent };
            selfLayer.Width = myContentSize.Width; selfLayer.Height = myContentSize.Height;
            myContent.Width = myContent.Width; myContent.Height = myContent.Height;
            overlay.Children.Add(selfLayer);
            Point location = this.TranslatePoint(new Point(0, 0), root);
            selfLayer.SetValue(Canvas.LeftProperty, location.X);
            selfLayer.SetValue(Canvas.TopProperty, location.Y);
            myContent.Visibility = Visibility.Visible;
            oldContent = root.Content;
            oy = Mouse.GetPosition(root).Y;
            root.Content = overlay;
            overlay.IsEnabled = false;
            orginValue = Value;

            AnimateContent(1, 1.08, new EventHandler((sender, e) => { overlay.IsEnabled = true; }));
            //mask.MouseDown += new MouseButtonEventHandler(_contentLayer_MouseDown);
            root.SizeChanged += new SizeChangedEventHandler(root_SizeChanged);
            myContent.Effect = new DropShadowEffect() { ShadowDepth = 0 };
            lastTick = Environment.TickCount;
            if (UseMouse)
            {
                root.MouseMove += new MouseEventHandler(root_MouseMove);
                root.MouseLeftButtonUp += new MouseButtonEventHandler(root_MouseLeftButtonUp);
                root.CaptureMouse();
            }
            else
            {
                root.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(root_ManipulationDelta);
                root.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(root_ManipulationCompleted);
            }
        }
Example #11
0
 public static void SetIsActive(this System.Windows.Controls.ContentControl control, bool value)
 {
     control.SetValue(IsActiveProperty, value);
 }
        private void UpdateLogger()
        {
            // Headers Column & Row definition
            EntriesGrid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(170)});
            EntriesGrid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(28)});

            var issueRows = new Dictionary<int, IssueRecord>();
            int rowCount = 1;
            foreach (IssueRecord issue in Logger.Records)
            {
                // Entries row Definition and binding to header definition
                var rowDef = new RowDefinition {Height = GridLength.Auto};
                EntriesGrid.RowDefinitions.Add(rowDef);

                // Add Row header content
                var content = new ContentControl
                                  {
                                      HorizontalAlignment = HorizontalAlignment.Stretch,
                                      VerticalAlignment = VerticalAlignment.Stretch,
                                      Content = issue.Issue,
                                      ContentTemplate = FindResource("IssueRowHeaderTemplate") as DataTemplate
                                  };
                content.SetValue(Grid.RowProperty, rowCount);
                content.SetValue(Grid.ColumnProperty, 0);
                EntriesGrid.Children.Add(content);

                // store which record goes in which row
                issueRows.Add(rowCount, issue);
                rowCount++;
            }

            int daysToShow = (EndDate.Date - StartDate.Date).Days;
            for (int i = 0; i < daysToShow; i++)
            {
                DateTime columnDate = StartDate.AddDays(i).Date;

                // Entry Column definition
                var columnDef = new ColumnDefinition {Width = new GridLength(100)};
                EntriesGrid.ColumnDefinitions.Add(columnDef);

                // Add column header content
                var content = new ContentControl
                                  {
                                      HorizontalAlignment = HorizontalAlignment.Stretch,
                                      VerticalAlignment = VerticalAlignment.Stretch,
                                      Content = columnDate,
                                      ContentTemplate = FindResource("ColumnHeaderTemplate") as DataTemplate
                                  };
                content.SetValue(Grid.ColumnProperty, i + 1);
                content.SetValue(Grid.RowProperty, 0);
                EntriesGrid.Children.Add(content);

                foreach (var row in issueRows)
                {
                    var entryContent = new DayLogControl
                                           {
                                               HorizontalAlignment = HorizontalAlignment.Stretch,
                                               VerticalAlignment = VerticalAlignment.Stretch
                                           };
                    entryContent.SetValue(Grid.RowProperty, row.Key);
                    entryContent.SetValue(Grid.ColumnProperty, i + 1);

                    DayLog dayLog = row.Value.DayLogs.SingleOrDefault(log => log.Date.Date.Equals(columnDate));
                    if (dayLog != null)
                    {
                        entryContent.Log = dayLog;
                    }

                    EntriesGrid.Children.Add(entryContent);
                }
            }
        }
        /// <summary>
        /// This method constructs the document page (visual) to print
        /// </summary>
        private DocumentPage ConstructPage(Grid content, int pageNumber)
        {
            if (content == null)
                return null;

            //Build the page inc header and footer
            Grid pageGrid = new Grid();

            //Header row
            AddGridRow(pageGrid, GridLength.Auto);

            //Content row
            AddGridRow(pageGrid, new GridLength(1.0d, GridUnitType.Star));

            //Footer row
            AddGridRow(pageGrid, GridLength.Auto);

            ContentControl pageHeader = new ContentControl();
            pageHeader.Content = this.CreateDocumentHeader();
            pageGrid.Children.Add(pageHeader);

            if (content != null)
            {
                content.SetValue(Grid.RowProperty, 1);
                pageGrid.Children.Add(content);
            }

            ContentControl pageFooter = new ContentControl();
            pageFooter.Content = CreateDocumentFooter(pageNumber + 1);
            pageFooter.SetValue(Grid.RowProperty, 2);

            pageGrid.Children.Add(pageFooter);

            double width = this.PageSize.Width - (this.PageMargin.Left + this.PageMargin.Right);
            double height = this.PageSize.Height - (this.PageMargin.Top + this.PageMargin.Bottom);

            pageGrid.Measure(new Size(width, height));
            pageGrid.Arrange(new Rect(this.PageMargin.Left, this.PageMargin.Top, width, height));

            //return new DocumentPage(pageGrid);
            return new DocumentPage(pageGrid, PageSize, new Rect(content.DesiredSize), new Rect(content.DesiredSize));
        }
        void PopulateContent()
        {
            this.panel.Items.Clear();

            if (this.Items != null)
            {

                // index 0 is header.
                ContentControl header = new ContentControl();
                header.Focusable = false;
                header.ContentTemplate = this.HeaderTemplate;
                header.SetValue(IndexProperty, 0);
                header.Drop += new DragEventHandler(OnSpacerDrop);
                this.panel.Items.Add(header);

                // index 1 is first spacer
                FrameworkElement startSpacer = CreateSpacer();
                this.panel.Items.Add(startSpacer);

                foreach (ModelItem item in this.Items)
                {
                    // index 2 + i*2 is itemView i
                    VirtualizedContainerService containerService = this.Context.Services.GetService<VirtualizedContainerService>();
                    UIElement itemView = containerService.GetContainer(item, this);
                    this.panel.Items.Add(itemView as UIElement);
                    // index 2 + i*2 + 1 is spacer i+1
                    FrameworkElement spacer = CreateSpacer();
                    this.panel.Items.Add(spacer);
                }
                // index 2 + count*2 is footer 
                ContentControl footer = new ContentControl();
                footer.ContentTemplate = this.FooterTemplate;
                footer.Focusable = true;
                footer.IsHitTestVisible = true;
                footer.IsTabStop = true;
                footer.SetValue(IndexProperty, addAtEndMarker);
                footer.Drop += new DragEventHandler(OnSpacerDrop);
                footer.LostFocus += new RoutedEventHandler(OnSpacerLostFocus);
                footer.GotFocus += new RoutedEventHandler(OnSpacerGotFocus);
                this.panel.Items.Add(footer);
                footer.Focusable = false;
            }
            UpdateHintTextVisibility(HintText);
        }
        /// <summary>
        /// Adds a cell to a grid
        /// </summary>
        /// <param name="grid">Grid to add teh cell to</param>
        /// <param name="column">Source column definition which contains binding info</param>
        /// <param name="item">The binding source</param>
        /// <param name="columnIndex">Column index</param>
        /// <param name="rowIndex">Row index</param>
        private void AddTableCell(Grid grid, DataGridColumn column, object item, int columnIndex, int rowIndex)
        {
            if (column is DataGridTemplateColumn)
            {
                DataGridTemplateColumn templateColumn = column as DataGridTemplateColumn;
                ContentControl contentControl = new ContentControl();

                contentControl.Focusable = true;
                contentControl.ContentTemplate = templateColumn.CellTemplate;
                contentControl.Content = item;

                contentControl.SetValue(Grid.ColumnProperty, columnIndex);
                contentControl.SetValue(Grid.RowProperty, rowIndex);

                grid.Children.Add(contentControl);
            }
            else if (column is DataGridTextColumn)
            {
                DataGridTextColumn textColumn = column as DataGridTextColumn;
                TextBlock text = new TextBlock { Text = "Text" };

                text.Style = this.TableCellTextStyle;
                text.TextTrimming = TextTrimming.CharacterEllipsis;
                text.DataContext = item;

                Binding binding = textColumn.Binding as Binding;

                //if (!string.IsNullOrEmpty(column.DisplayFormat))
                //binding.StringFormat = column.DisplayFormat;

                text.SetBinding(TextBlock.TextProperty, binding);

                // If General Account Fund or Trust Account Fund make Center
                //if (columnIndex == 4 || columnIndex == 5)
                //{
                //    text.TextAlignment = TextAlignment.Center;
                //}

                // If General Account Fund or Trust Account Fund make Center
                if (rowIndex == 0)
                {
                    text.TextAlignment = TextAlignment.Center;
                    text.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);

                }

                text.SetValue(Grid.ColumnProperty, columnIndex);
                text.SetValue(Grid.RowProperty, rowIndex);

                grid.Children.Add(text);
            }
        }
 public static void SetSharedResources(ContentControl element, ResourceUri value)
 {
     element.SetValue(SharedResourcesProperty, value);
 }
Example #17
0
 public static void SetOnSelectedTabChanged(ContentControl element, bool value)
 {
     element.SetValue(OnDataContextChangedProperty, value);
 }
 public static void SetContentChangedAnimation(ContentControl element, Storyboard value)
 {
     element.SetValue(ContentChangedAnimationProperty, value);
 }
Example #19
0
		public void XamlTemplateBinding_Reuse ()
		{
			// If we re-apply a TemplateBinding, a NullReferenceException
			// is thrown in their Attach method. Probably because they cleared
			// everything out in their Detach method (or equivalent).
			ContentControl c = (ContentControl) XamlReader.Load (@"
<ContentControl
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" 
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" 
    xmlns:clr=""clr-namespace:Mono.Moonlight"">
    <ContentControl.Template>
        <ControlTemplate>
            <Canvas>
                <ContentControl x:Name=""Parent"" Width=""{TemplateBinding Width}"" />
            </Canvas>
        </ControlTemplate>
    </ContentControl.Template>
</ContentControl>");

			c.ApplyTemplate ();
			var cc = c.FindFirstChild<ContentControl> ();
			var binding = (TemplateBindingExpression) cc.ReadLocalValue (ContentControl.WidthProperty);
			cc.ClearValue (ContentControl.ContentProperty);
			cc = new ContentControl ();

			Assert.Throws<NullReferenceException> (() =>
				cc.SetValue (ContentControl.ContentProperty, binding)
			, "#1");
		}
        /// <summary>
        /// Adds a cell to a grid
        /// </summary>
        /// <param name="grid">Grid to add teh cell to</param>
        /// <param name="column">Source column definition which contains binding info</param>
        /// <param name="item">The binding source</param>
        /// <param name="columnIndex">Column index</param>
        /// <param name="rowIndex">Row index</param>
        private void AddTableCell(Grid grid, DataGridColumn column, object item, int columnIndex, int rowIndex)
        {
            if (column is DataGridTemplateColumn)
            {
                DataGridTemplateColumn templateColumn = column as DataGridTemplateColumn;
                ContentControl contentControl = new ContentControl();

                contentControl.Focusable = true;
                contentControl.ContentTemplate = templateColumn.CellTemplate;
                contentControl.Content = item;

                contentControl.SetValue(Grid.ColumnProperty, columnIndex);
                contentControl.SetValue(Grid.RowProperty, rowIndex);

                grid.Children.Add(contentControl);
            }
            else if (column is DataGridTextColumn)
            {
                DataGridTextColumn textColumn = column as DataGridTextColumn;
                TextBlock text = new TextBlock { Text = "Text" };
                text.Padding = new Thickness(5);

                //text.Style = this.TableCellTextStyle;

                text.TextTrimming = TextTrimming.CharacterEllipsis;
                text.DataContext = item;

                Binding binding = textColumn.Binding as Binding;

                //if (!string.IsNullOrEmpty(column.DisplayFormat))
                //binding.StringFormat = column.DisplayFormat;

                text.SetBinding(TextBlock.TextProperty, binding);

                //If General Account Fund or Trust Account Fund make right

                if (columnIndex == 4)
                {
                    text.TextAlignment = TextAlignment.Right;
                    text.Text += "     ";
                }
                if (columnIndex == 5)
                {
                    text.TextAlignment = TextAlignment.Right;
                    text.Text += "      ";
                }

                // If General Account Fund or Trust Account Fund make Center
                if (rowIndex == 0)
                {
                    text.TextAlignment = TextAlignment.Center;
                    text.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);
                }
                if (columnIndex == 2 && rowIndex > 1)
                {
                    //text.Text = string.Empty;
                    //for (int i = 0; i < 300; i++)
                    //{
                    //    text.Text += i.ToString();
                    //}
                    //string[] splitter = new string[] { "\r\n" };
                    //string[] splitMessage = text.Text.Split(splitter, StringSplitOptions.None);
                    //text.Text = string.Empty;

                    //for (int index = 0; index < splitMessage.Length; index++)
                    //{
                    //    if (index > 0)
                    //    {
                    //        text.Text += Constants.MULTI_LINE_SEPARATOR;
                    //    }
                    //        text.Text += splitMessage[index];
                    //}
                }

                text.SetValue(Grid.ColumnProperty, columnIndex);
                text.SetValue(Grid.RowProperty, rowIndex);
                grid.Children.Add(text);
            }
        }
Example #21
0
        public void RegionGetsAddedInRegionManagerWhenAddedIntoAScope()
        {
            var mappings = new RegionAdapterMappings();
            mappings.RegisterMapping(typeof(DependencyObject), new MockRegionAdapter());

            RegionManager regionManager = new RegionManager(mappings);
            var regionScopeControl = new ContentControl();
            RegionManager.SetRegionManager(regionScopeControl, regionManager);

            var control = new ContentControl();
            control.SetValue(RegionManager.RegionNameProperty, "TestRegion");

            Assert.IsFalse(regionManager.Regions.ContainsKey("TestRegion"));
            regionScopeControl.Content = control;
            Assert.IsTrue(regionManager.Regions.ContainsKey("TestRegion"));
            Assert.IsNotNull(regionManager.Regions["TestRegion"]);
        }
        public override void AddConfigUI(System.Windows.Controls.Grid grid)
        {
            TextBlock label;

            #region Header
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Grid g = new Grid();
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            label = new TextBlock()
            {
                Text = Name,
                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                Margin = new Thickness(2, 10, 2, 2),
                FontWeight = FontWeights.Bold,
                TextTrimming = TextTrimming.WordEllipsis
            };
            g.Children.Add(label);
            g.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            g.SetValue(Grid.ColumnSpanProperty, 2);
            grid.Children.Add(g);
            #endregion

            #region Type
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label = new TextBlock()
            {
                Text = Resources.Strings.LabelType,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            label = new TextBlock()
            {
                Text = Type.ToString(),
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            label.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(label);
            #endregion

            #region Layer name
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label = new TextBlock()
            {
                Text = Resources.Strings.LabelLayerName,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            TextBox tb = new TextBox()
            {
                Text = LayerName,
                Margin = new Thickness(2),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
            };
            tb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            tb.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(tb);
            tb.TextChanged += (s, e) =>
            {
                LayerName = tb.Text;
            };
            #endregion

            #region Popups config
            if (SupportsJobResource && LayerInfos != null && LayerInfos.Count > 0 && LayerInfos.All(l => l.Fields != null && l.Fields.Count > 0))
            {
                grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                label = new TextBlock()
                {
                    Text = Resources.Strings.LabelPopUps,
                    Margin = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                Button popupButton = new Button
                                        {
                                            Content = new Image
                                            {
                                                Source = new BitmapImage(new Uri("/ESRI.ArcGIS.Mapping.GP;component/Images/Show_Popup16.png", UriKind.Relative)),
                                                Stretch = Stretch.None,
                                                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                                                HorizontalAlignment = System.Windows.HorizontalAlignment.Center
                                            },
                                            Width = 22,
                                            HorizontalAlignment = HorizontalAlignment.Left,
                                            Style = Application.Current.Resources["SimpleButtonStyle"] as Style
                                        };
                ToolTipService.SetToolTip(popupButton, Resources.Strings.ConfigurePopupFieldAliasesAndVisibility);
                popupButton.Click += popupButton_Click;
                popupButton.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                popupButton.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(popupButton);
            }
            #endregion

            #region Opacity
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label = new TextBlock()
            {
                Text = Resources.Strings.LabelTransparency,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Top
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);

            ContentControl sliderOpacity = new ContentControl()
            {
                DataContext = this,
                Style = ResourceUtility.LoadEmbeddedStyle("Themes/HorizontalTransparencySlider.xaml", "TransparencySliderStyle")
            };
            sliderOpacity.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            sliderOpacity.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(sliderOpacity);
            #endregion
        }
        /// <summary>
        /// Adds a cell to a grid
        /// </summary>
        /// <param name="grid">Grid to add teh cell to</param>
        /// <param name="column">Source column definition which contains binding info</param>
        /// <param name="item">The binding source</param>
        /// <param name="columnIndex">Column index</param>
        /// <param name="rowIndex">Row index</param>
        private bool AddTableCell(Grid grid, DependencyObject column, object item, int columnIndex, int rowIndex)
        {
            if (column is DataGridColumn)
            {
                var datagridcolumn = column as DataGridColumn;
                if (datagridcolumn.Visibility != Visibility.Visible)
                    return false;

                if (column is DataGridTemplateColumn)
                {
                    DataGridTemplateColumn templateColumn = column as DataGridTemplateColumn;
                    ContentControl contentControl = new ContentControl();

                    contentControl.Focusable = true;
                    contentControl.ContentTemplate = templateColumn.CellTemplate;
                    contentControl.Content = item;

                    contentControl.SetValue(Grid.ColumnProperty, columnIndex);
                    contentControl.SetValue(Grid.RowProperty, rowIndex);

                    grid.Children.Add(contentControl);
                    return true;
                }
                else if (column is DataGridTextColumn)
                {
                    DataGridTextColumn textColumn = column as DataGridTextColumn;
                    TextBlock text = new TextBlock { Text = "Text" };

                    text.Style = this.TableCellTextStyle;
                    if (WrapText)
                        text.TextWrapping = TextWrapping.Wrap;
                    else
                        text.TextTrimming = TextTrimming.CharacterEllipsis;
                    text.DataContext = item;

                    Binding binding = textColumn.Binding as Binding;

                    SetOtherProperties(text, textColumn);

                    //if (!string.IsNullOrEmpty(column.DisplayFormat))
                    //binding.StringFormat = column.DisplayFormat;

                    text.SetBinding(TextBlock.TextProperty, binding);

                    text.SetValue(Grid.ColumnProperty, columnIndex);
                    text.SetValue(Grid.RowProperty, rowIndex);

                    grid.Children.Add(text);
                    return true;
                }
            }
            if (column is GridViewColumn)
            {
                var gridviewcolumn = column as GridViewColumn;
                if (gridviewcolumn.ActualWidth < 2)
                    return false;

                if (gridviewcolumn.CellTemplate != null)
                {
                    ContentControl contentControl = new ContentControl();

                    contentControl.Focusable = true;
                    contentControl.ContentTemplate = gridviewcolumn.CellTemplate;
                    contentControl.Content = item;

                    contentControl.SetValue(Grid.ColumnProperty, columnIndex);
                    contentControl.SetValue(Grid.RowProperty, rowIndex);

                    grid.Children.Add(contentControl);
                    return true;
                }
                else //if (column is DataGridTextColumn)
                {
                    //DataGridTextColumn textColumn = column as DataGridTextColumn;
                    TextBlock text = new TextBlock { Text = "Text" };

                    text.Style = this.TableCellTextStyle;
                    if (WrapText)
                        text.TextWrapping = TextWrapping.Wrap;
                    else
                        text.TextTrimming = TextTrimming.CharacterEllipsis;
                    text.DataContext = item;

                    Binding binding = gridviewcolumn.DisplayMemberBinding as Binding;

                    //if (!string.IsNullOrEmpty(column.DisplayFormat))
                    //binding.StringFormat = column.DisplayFormat;

                    text.SetBinding(TextBlock.TextProperty, binding);

                    text.SetValue(Grid.ColumnProperty, columnIndex);
                    text.SetValue(Grid.RowProperty, rowIndex);

                    grid.Children.Add(text);
                    return true;
                }
            }
            return false;
        }
        private void Redraw()
        {
            var properties = TypeDescriptor.GetProperties(viewModel.CollectionElementType).OfType<PropertyDescriptor>().Where(x => x.Attributes.OfType<ConfigurationPropertyAttribute>().Any()).ToArray();

            for (int n = 0; n <= viewModel.ChildElements.Count() + 1; n++)
            {
                Collection.RowDefinitions.Add(new RowDefinition());
            }

            int i = 0;
            foreach (var property in properties)
            {
                var label = new Label() { Content = property.DisplayName };
                Collection.Children.Add(label);
                label.SetValue(Grid.RowProperty, 0);
                label.SetValue(Grid.ColumnProperty, i);


                var gridSplitter = new GridSplitter() { Width = 2, HorizontalAlignment = HorizontalAlignment.Right };
                Collection.Children.Add(gridSplitter);
                gridSplitter.Focusable = false;
                gridSplitter.SetValue(Grid.RowProperty, 0);
                gridSplitter.SetValue(Grid.ColumnProperty, i);
                gridSplitter.SetValue(Grid.RowSpanProperty, viewModel.ChildElements.Count() + 1);
                i++;
            }

            ContextMenuButton addButton = new ContextMenuButton();
            Collection.Children.Add(addButton);
            CommandModel addCommand = viewModel.AddCommands.First();
            addButton.Command = addCommand;
            addButton.SetValue(Grid.RowProperty, 0);
            addButton.SetValue(Grid.ColumnProperty, i);
            addButton.Style = FindResource("ContextAdderButtonMenuStyle") as Style;
            addButton.VerticalAlignment = VerticalAlignment.Center;
            addButton.SetValue(AutomationProperties.AutomationIdProperty, addCommand.Title);
            
            int j = 1;
            foreach (var element in viewModel.ChildElements)
            {
                i = 0;
                foreach (var propertyDescriptor in properties)
                {
                    var property = element.Property(propertyDescriptor.Name);

                    ContentControl contentControl = new ContentControl();
                    contentControl.Focusable = false;
                    Collection.Children.Add(contentControl);
                    contentControl.SetValue(ContentControl.ContentProperty, property.BindableProperty);
                    contentControl.SetValue(Grid.RowProperty, j);
                    contentControl.SetValue(Grid.ColumnProperty, i);

                    i++;
                }

                Button deleteButton = new Button();
                Collection.Children.Add(deleteButton);
                CommandModel deleteCommand = element.Commands.Where(x => x.Placement == CommandPlacement.ContextDelete).First();
                deleteButton.Command = deleteCommand;
                deleteButton.SetValue(Grid.RowProperty, j);
                deleteButton.SetValue(Grid.ColumnProperty, i);
                deleteButton.Style = FindResource("DeleteButtonStyle") as Style;
                deleteButton.VerticalAlignment = VerticalAlignment.Center;
                deleteButton.SetValue(AutomationProperties.AutomationIdProperty, deleteCommand.Title);

                j++;
            }
        }
        /// <summary>
        /// Adds a cell to a grid
        /// </summary>
        /// <param name="grid">Grid to add teh cell to</param>
        /// <param name="column">Source column definition which contains binding info</param>
        /// <param name="item">The binding source</param>
        /// <param name="columnIndex">Column index</param>
        /// <param name="rowIndex">Row index</param>
        private void AddTableCell(Grid grid, DataGridColumn column, object item, int columnIndex, int rowIndex)
        {
            if (column is DataGridTemplateColumn)
            {
                DataGridTemplateColumn templateColumn = column as DataGridTemplateColumn;
                ContentControl contentControl = new ContentControl();

                contentControl.Focusable = true;
                contentControl.ContentTemplate = templateColumn.CellTemplate;
                contentControl.Content = item;

                contentControl.SetValue(Grid.ColumnProperty, columnIndex);
                contentControl.SetValue(Grid.RowProperty, rowIndex);

                grid.Children.Add(contentControl);
            }
            else if (column is DataGridTextColumn)
            {
                DataGridTextColumn textColumn = column as DataGridTextColumn;
                TextBlock text = new TextBlock { Text = "Text" };

                text.Style = this.TableCellTextStyle;
                text.TextTrimming = TextTrimming.CharacterEllipsis;
                text.DataContext = item;

                Binding binding = textColumn.Binding as Binding;

                //if (!string.IsNullOrEmpty(column.DisplayFormat))
                //binding.StringFormat = column.DisplayFormat;

                text.SetBinding(TextBlock.TextProperty, binding);

                text.SetValue(Grid.ColumnProperty, columnIndex);
                text.SetValue(Grid.RowProperty, rowIndex);

                grid.Children.Add(text);
            }
        }
Example #26
0
 public static void SetModuleInfo(ContentControl control, ModuleInfo moduleInfo)
 {
     control.SetValue(ModuleInfoProperty, moduleInfo);
 }
        public override void AddConfigUI(System.Windows.Controls.Grid grid)
        {
            base.AddConfigUI(grid);
            #region Layer name
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            TextBlock layerName = new TextBlock()
            {
                Text = Resources.Strings.LabelLayerName,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            layerName.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(layerName);
            TextBox labelTextBox = new TextBox()
            {
                Text = LayerName == null ? string.Empty : LayerName,
                Margin = new Thickness(2),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
            };
            labelTextBox.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            labelTextBox.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(labelTextBox);
            labelTextBox.TextChanged += (s, e) =>
            {
                LayerName = labelTextBox.Text;
            };
            #endregion
            #region Renderer
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            TextBlock label2 = new TextBlock()
            {
                Text = Resources.Strings.LabelRenderer,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label2.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label2);
            Button rendererButton = null;
            if (GeometryType == Core.GeometryType.Unknown)
            {
                TextBlock tb = new TextBlock() { Text = Resources.Strings.NotAvailable, VerticalAlignment = VerticalAlignment.Center };
                ToolTipService.SetToolTip(tb, Resources.Strings.GeometryTypeIsNotKnown);
                tb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                tb.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(tb);
            }
            else
            {
                rendererButton = new Button()
                {
                    Content = new Image()
                               {
                                   Source = new BitmapImage(new Uri("/ESRI.ArcGIS.Mapping.GP;component/Images/ColorScheme16.png", UriKind.Relative)),
                                   Stretch = Stretch.None,
                                   VerticalAlignment = System.Windows.VerticalAlignment.Center,
                                   HorizontalAlignment = System.Windows.HorizontalAlignment.Center
                               },
                    Width = 22,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Style = Application.Current.Resources["SimpleButtonStyle"] as Style,
                    IsEnabled = (Mode == InputMode.SketchLayer),
                };
                ToolTipService.SetToolTip(rendererButton, Resources.Strings.ConfigureRenderer);
                rendererButton.Click += rendererButton_Click;
                rendererButton.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                rendererButton.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(rendererButton);
            }
            #endregion
            #region Popup Config
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label2 = new TextBlock()
            {
                Text = Resources.Strings.LabelPopUps,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label2.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label2);
            Button popupButton = null;
            if (Layer == null)
            {
                TextBlock tb = new TextBlock() { Text = Resources.Strings.NotAvailable, VerticalAlignment = VerticalAlignment.Center };
                ToolTipService.SetToolTip(tb, Resources.Strings.FieldInformationIsNotKnown);
                tb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                tb.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(tb);
            }
            else
            {
                popupButton = new Button()
                {
                    Content = new Image()
                    {
                        Source = new BitmapImage(new Uri("/ESRI.ArcGIS.Mapping.GP;component/Images/Show_Popup16.png", UriKind.Relative)),
                        Stretch = Stretch.None,
                        VerticalAlignment = System.Windows.VerticalAlignment.Center,
                        HorizontalAlignment = System.Windows.HorizontalAlignment.Center
                    },
                    Width = 22,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Style = Application.Current.Resources["SimpleButtonStyle"] as Style,
                    IsEnabled = (Mode == InputMode.SketchLayer),
                };
                ToolTipService.SetToolTip(popupButton, Resources.Strings.ConfigurePopupFieldAliasesAndVisibility);
                popupButton.Click += popupButton_Click;
                popupButton.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                popupButton.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(popupButton);
            }
            #endregion

            #region Transparency
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label2 = new TextBlock()
            {
                Text = Resources.Strings.LabelTransparency,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Top
            };
            label2.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label2);

            ContentControl slider = new ContentControl()
            {
                DataContext = this,
                IsEnabled = (Mode == InputMode.SketchLayer),
                Style = ResourceUtility.LoadEmbeddedStyle("Themes/HorizontalTransparencySlider.xaml", "TransparencySliderStyle")
            };
            //Slider slider = new Slider()
            //{
            //    DataContext = this,
            //    IsEnabled = (Mode == InputMode.SketchLayer),
            //    Orientation = Orientation.Horizontal,
            //    Width = 145,
            //    Minimum = 0,
            //    Maximum = 1
            //};
            //slider.SetBinding(Slider.ValueProperty,
            //    new System.Windows.Data.Binding("Opacity") { Mode = System.Windows.Data.BindingMode.TwoWay });
            slider.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            slider.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(slider);
            #endregion

            if (Input)
            {
                #region Input Mode
                grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                TextBlock label = new TextBlock()
                {
                    Text = Resources.Strings.LabelInputFeatures,
                    Margin = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);

                grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                StackPanel panel = new StackPanel()
                {
                    Orientation = System.Windows.Controls.Orientation.Vertical,
                    Margin = new Thickness(15, 0, 0, 0),
                };
                panel.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                panel.SetValue(Grid.ColumnSpanProperty, 2);
                RadioButton interactive = new RadioButton()
                {
                    Content = Resources.Strings.Interactively,
                    IsChecked = (Mode == InputMode.SketchLayer),
                    Margin = new Thickness(2),
                    Foreground = Application.Current.Resources["DesignHostBackgroundTextBrush"] as Brush
                };
                panel.Children.Add(interactive);
                RadioButton selection = new RadioButton()
                {
                    Content = Resources.Strings.BySelectingLayerFromMap,
                    IsChecked = (Mode == InputMode.SelectExistingLayer),
                    Margin = new Thickness(2),
                    Foreground = Application.Current.Resources["DesignHostBackgroundTextBrush"] as Brush
                };
                panel.Children.Add(selection);
                RadioButton fromExtent = null;
                if (GeometryType == Core.GeometryType.Polygon)
                {
                    fromExtent = new RadioButton()
                    {
                        Content = Resources.Strings.FromMapExtent,
                        IsChecked = (Mode == InputMode.CurrentExtent),
                        Margin = new Thickness(2),
                        Foreground = Application.Current.Resources["DesignHostBackgroundTextBrush"] as Brush
                    };
                    panel.Children.Add(fromExtent);

                }
                interactive.Checked += (a, b) =>
                {
                    Mode = InputMode.SketchLayer;
                    selection.IsChecked = false;
                    if (fromExtent != null)
                        fromExtent.IsChecked = false;
                    if (popupButton != null)
                        popupButton.IsEnabled = true;
                    if (rendererButton != null)
                        rendererButton.IsEnabled = true;
                    //if (slider != null)
                    //    slider.IsEnabled = true;
                };
                selection.Checked += (a, b) =>
                 {
                     Mode = InputMode.SelectExistingLayer;
                     interactive.IsChecked = false;
                     if (fromExtent != null)
                         fromExtent.IsChecked = false;
                     if (popupButton != null)
                         popupButton.IsEnabled = false;
                     if (rendererButton != null)
                         rendererButton.IsEnabled = false;
                     //if (slider != null)
                     //    slider.IsEnabled = false;
                 };
                if (fromExtent != null)
                {
                    fromExtent.Checked += (a, b) =>
                     {
                         Mode = InputMode.CurrentExtent;
                         interactive.IsChecked = false;
                         selection.IsChecked = false;
                         if (popupButton != null)
                             popupButton.IsEnabled = false;
                         if (rendererButton != null)
                             rendererButton.IsEnabled = false;
                         //if (slider != null)
                         //    slider.IsEnabled = false;
                     };
                }
                grid.Children.Add(panel);
                #endregion
            }
        }
		public void ShouldSerializeContent2 ()
		{
			ContentControl c = new ContentControl ();
			Assert.IsFalse (c.ShouldSerializeContent (), "1");
			Assert.IsFalse (c.ShouldSerializeContent (), "1 1");
			c.SetValue (ContentControl.ContentProperty, null);
			Assert.IsTrue (c.ShouldSerializeContent (), "2");
			c.SetValue (ContentControl.ContentProperty, "");
			Assert.IsTrue (c.ShouldSerializeContent (), "3");
			c.SetValue (ContentControl.ContentProperty, null);
			Assert.IsTrue (c.ShouldSerializeContent (), "4");
			c.SetValue (ContentControl.ContentProperty, 1);
			Assert.IsTrue (c.ShouldSerializeContent (), "5");
		}