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


C# ContentControl.SetBinding方法代码示例

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


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

示例1: ContentAdorner

        // Be sure to call the base class constructor.
        public ContentAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            this.children = new VisualCollection(this);

            //
            // Create the content control
            //
            var contentControl = new ContentControl();

            //
            // Bind the content control to the Adorner's ContentTemplate property, so we know what to display
            //
            var contentTemplateBinding = new Binding();
            contentTemplateBinding.Path = new PropertyPath(AdornerContentTemplateProperty);
            contentTemplateBinding.Source = adornedElement;
            contentControl.SetBinding(ContentControl.ContentTemplateProperty, contentTemplateBinding);

            //
            // Add the ContentControl as a child
            //
            this.child = contentControl;
            this.children.Add(this.child);
            this.AddLogicalChild(this.child);
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:26,代码来源:ContentAdorner.cs

示例2: GenerateElement

 protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
 { 
   var binding = new Binding(((Binding)Binding).Path.Path); 
   binding.Source = dataItem; 
  var content = new ContentControl(); 
  content.ContentTemplate = (DataTemplate)cell.FindResource(TemplateName); 
  content.SetBinding(ContentControl.ContentProperty, binding); return content; 
 } 
开发者ID:mukeshdepani,项目名称:ParaRD,代码行数:8,代码来源:CustomBoundColumn.cs

示例3: Update

        /// <summary>
        /// Updates the specified binding.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <param name="dataContext">The data context.</param>
        /// <param name="value">The value.</param>
        public static void Update(this BindingBase binding, object dataContext, object value)
        {
            Binding b = binding as Binding;
            if (b != null && b.Mode != BindingMode.TwoWay)
            {
                b.Mode = BindingMode.TwoWay;
            }

            ContentControl contentControl = new ContentControl();
            contentControl.DataContext = dataContext;
            contentControl.SetBinding(ContentControl.ContentProperty, b);
            contentControl.Content = value;
        }
开发者ID:ruisebastiao,项目名称:Elysium-Extra,代码行数:19,代码来源:BindingBaseExtensions.cs

示例4: Resolve

        /// <summary>
        /// Resolves the specified binding.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <param name="dataContext">The data context.</param>
        /// <returns>The result of the resolved binding.</returns>
        public static object Resolve(this BindingBase binding, object dataContext)
        {
            ContentControl contentControl = new ContentControl();
            contentControl.DataContext = dataContext;
            contentControl.SetBinding(ContentControl.ContentProperty, binding);

            if (!string.IsNullOrEmpty(binding.StringFormat))
            {
                contentControl.Content = string.Format(binding.StringFormat, contentControl.Content);
            }

            return contentControl.Content;
        }
开发者ID:ruisebastiao,项目名称:Elysium-Extra,代码行数:19,代码来源:BindingBaseExtensions.cs

示例5: RunTest

		void RunTest ()
		{
			var c = new ObservableCollection<int> { 1, 2, 3, 4, 5 };
			WeakControl = new ContentControl ();
			WeakControl.SetBinding (ContentControl.ContentProperty, new Binding ("[0]") { Source = c });
			Holder = c;

			GCAndInvoke (() => {
				if (WeakControl != null)
					Fail ("The control should be collected");
				else
					Succeed ();
			});
		}
开发者ID:dfr0,项目名称:moon,代码行数:14,代码来源:Test.cs

示例6: UIBoundToCustomerIndexer

        public UIBoundToCustomerIndexer()
        {
            var stack = new StackPanel();
            Content = stack;

            var textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("FirstName"));
            stack.Children.Add(textBlock);

            var contentControl = new ContentControl();
            contentControl.SetBinding(ContentControl.ContentProperty, new Binding("[0].Quantity"));
            stack.Children.Add(contentControl);

            contentControl = new ContentControl();
            contentControl.SetBinding(ContentControl.ContentProperty, new Binding("[text].Quaity")); //purposefully misspelled
            stack.Children.Add(contentControl);
        }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:17,代码来源:UIBoundToCustomerIndexer.cs

示例7: UIBoundToCustomerWithContentControlAndTriggers

        public UIBoundToCustomerWithContentControlAndTriggers()
        {
            var stack = new StackPanel();
            Content = stack;

            var textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("FirstName"));
            stack.Children.Add(textBlock);

            textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("LastName"));
            stack.Children.Add(textBlock);

            var contentControl = new ContentControl {ContentTemplate = CreateItemTemplate()};
            contentControl.SetBinding(ContentControl.ContentProperty, new Binding("MailingAddress"));
            stack.Children.Add(contentControl);
        }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:17,代码来源:UIBoundToCustomerWithContentControlAndTriggers.cs

示例8: ControlWithExistingBindingOnContentWithNullValueThrows

        public void ControlWithExistingBindingOnContentWithNullValueThrows()
        {
            var control = new ContentControl();
            Binding binding = new Binding("ObjectContents");
            binding.Source = new SimpleModel() { ObjectContents = null };
            control.SetBinding(ContentControl.ContentProperty, binding);

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            try
            {
                var region = (MockPresentationRegion)adapter.Initialize(control, "Region1");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ContentControl's Content property is not empty.");
            }
        }
开发者ID:selvendiranj,项目名称:compositewpf-copy,代码行数:20,代码来源:ContentControlRegionAdapterFixture.cs

示例9: CreateOrUnhideDockableContent

        private void CreateOrUnhideDockableContent(ContentTypes contentType, string title, string viewPropertyName, object parent)
        {
            if (!this.dockableContents.Keys.Contains(contentType))
            {
                DockableContent dockableContent = new DockableContent();

                ContentControl contentControl = new ContentControl();

                dockableContent.IsCloseable = true;
                dockableContent.HideOnClose = false;

                dockableContent.Title = title;

                dockableContent.Content = contentControl;

                if (parent is ResizingPanel)
                {
                    DockablePane dockablePane = new DockablePane();
                    dockablePane.Items.Add(dockableContent);
                    ResizingPanel resizingPanel = parent as ResizingPanel;

                    switch (contentType)
                    {
                        case ContentTypes.PropertyInspector:
                            resizingPanel.Children.Add(dockablePane);
                            ResizingPanel.SetResizeWidth(dockablePane, new GridLength(300));
                            break;
                        case ContentTypes.Outline:
                            resizingPanel.Children.Insert(1, dockablePane);
                            ResizingPanel.SetResizeWidth(dockablePane, new GridLength(250));
                            break;
                        case ContentTypes.Toolbox:
                            resizingPanel.Children.Insert(0, dockablePane);
                            ResizingPanel.SetResizeWidth(dockablePane, new GridLength(250));
                            break;
                    }
                }
                else if (parent is DockablePane)
                {
                    DockablePane dockablePane = parent as DockablePane;
                    dockablePane.Items.Add(dockableContent);
                    if (dockablePane.Parent == null)
                    {
                        this.verticalResizingPanel.Children.Add(dockablePane);
                    }
                }

                Binding dataContextBinding = new Binding(viewPropertyName);
                dockableContent.SetBinding(DockableContent.DataContextProperty, dataContextBinding);

                Binding contentBinding = new Binding(".");
                contentControl.SetBinding(ContentControl.ContentProperty, contentBinding);

                this.dockableContents[contentType] = dockableContent;

                dockableContent.Closed += delegate(object sender, EventArgs args)
                {
                    contentControl.Content = null;
                    this.dockableContents[contentType].DataContext = null;
                    this.dockableContents.Remove(contentType);
                };
            }
            else
            {
                if (this.dockableContents[contentType].State == DockableContentState.Hidden)
                {
                    this.dockableContents[contentType].Show();
                }
            }
        }
开发者ID:yinqunjun,项目名称:WorkflowFoundation.40.45.Development,代码行数:70,代码来源:MainWindowViewModel.cs

示例10: AddTabItem

        /// <summary>
        /// Adds <see cref="TabItem"/> for the content object
        /// </summary>
        /// <param name="item">Content of the <see cref="TabItems"/></param>
        private void AddTabItem(object item)
        {
            ContentControl contentControl = new ContentControl();
            TabItem tab = new TabItem
            {
                DataContext = item,
                Content = contentControl,
                HeaderTemplate = _tabControl.ItemTemplate
            };

            contentControl.SetBinding(ContentControl.ContentProperty, new Binding());
            tab.SetBinding(TabItem.HeaderProperty, new Binding());

            _tabControl.Items.Add(tab);
        }
开发者ID:harriganjames,项目名称:Finances,代码行数:19,代码来源:TabItemGeneratorBehavior.cs

示例11: DataContext_PreferFrameworkElementParentOverMentor

		public void DataContext_PreferFrameworkElementParentOverMentor ()
		{
			var root1 = new Canvas { DataContext = 1 };
			var root2 = new Canvas { DataContext = 2 };

			var target = new ContentControl ();
			target.SetBinding (FrameworkElement.DataContextProperty, new Binding ());

			// This sets FrameworkElement.Parent
			root1.Children.Add (target);

			// This sets a new Mentor
			ToolTipService.SetPlacementTarget (root2, target);
			CreateAsyncTest (root1,
				() => {
					// We should be using the DataContext from FrameworkElement.Parent, not the mentor
					Assert.AreEqual (1, target.DataContext, "#1");
					// We pick up changes on the datacontext
					root1.DataContext = 2;
				}, () => {
					Assert.AreEqual (2, target.DataContext, "#2");

					// We ignore changes on the mentors datacontext
					root2.DataContext = 4;
				}, () => {
					Assert.AreEqual (2, target.DataContext, "#3");
				}
			);
		}
开发者ID:dfr0,项目名称:moon,代码行数:29,代码来源:BindingTest.cs

示例12: InDesignModeSettingViewModelWithGoodBindingGivesAppropriateMessage

        public void InDesignModeSettingViewModelWithGoodBindingGivesAppropriateMessage()
        {
            Execute.InDesignMode = true;

            var element = new ContentControl();
            var vm = new TestViewModel();

            var binding = new Binding("SubViewModel");
            binding.Source = vm;
            element.SetBinding(View.ModelProperty, binding);

            Assert.IsInstanceOf<TextBlock>(element.Content);

            var content = (TextBlock)element.Content;
            Assert.AreEqual("View for TestViewModel.SubViewModel", content.Text);
        }
开发者ID:modulexcite,项目名称:Stylet,代码行数:16,代码来源:ViewTests.cs

示例13: GetSelectableValueFromItem

        // Find out the value of the item using SelectedValuePath.
        // If there is no SelectedValuePath then item itself is
        // it's value or the innerText in case of XML node.
        private object GetSelectableValueFromItem(object item, ContentControl dummyElement)
        {
            bool useXml = item is XmlNode;
            Binding itemBinding = new Binding();
            itemBinding.Source = item;
            if (useXml)
            {
                itemBinding.XPath = SelectedValuePath;
                itemBinding.Path = new PropertyPath("/InnerText");
            }
            else
            {
                itemBinding.Path = new PropertyPath(SelectedValuePath);
            }

            // optimize for case where there is no SelectedValuePath (meaning
            // that the value of the item is the item itself, or the InnerText
            // of the item)
            if (string.IsNullOrEmpty(SelectedValuePath))
            {
                // when there's no SelectedValuePath, the binding's Path
                // is either empty (CLR) or "/InnerText" (XML)
                string path = itemBinding.Path.Path;
                Debug.Assert(String.IsNullOrEmpty(path) || path == "/InnerText");
                if (string.IsNullOrEmpty(path))
                {
                    // CLR - item is its own selected value
                    return item;
                }
                else
                {
                    return GetInnerText(item);
                }
            }

            dummyElement.SetBinding(ContentControl.ContentProperty, itemBinding);
            return dummyElement.Content;
        }
开发者ID:kasicass,项目名称:kasicass,代码行数:41,代码来源:RibbonGallery.cs

示例14: GlyphIconButton_WithPopup

		public GlyphIconButton_WithPopup()
		{
			Popup = new Popup()
			{
				AllowsTransparency = true,
			};
			var contentControl = new ContentControl()
			{
				Focusable = false,
				IsTabStop = false,

			};
			contentControl.SetBinding(ContentProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(PopupContent)}")});
			contentControl.SetBinding(ContentTemplateProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(PopupContentTemplate)}")});
			Popup.Child = new Border
			{
				Child = contentControl,
				Effect = new DropShadowEffect() {BlurRadius = 10, Color = Colors.Black, Opacity = 1, ShadowDepth = 0},
				Margin = new Thickness(10),
			};
			Popup.SetBinding(Popup.IsOpenProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(IsOpened)}")});
			Popup.SetBinding(Popup.PlacementTargetProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(PopupPlacementTarget)}")});
			Popup.SetBinding(Popup.StaysOpenProperty, new Binding() {Source = this, Path = new PropertyPath($"{nameof(StaysOpen)}")});
			Popup.Placement = PlacementMode.Bottom;
			AddLogicalChild(Popup);
			Click += GlyphIconButton_WithPopup_Click;
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:27,代码来源:GlyphIconButton_WithPopup.xaml.cs

示例15: BuildGUIConfiguration

        public FrameworkElement BuildGUIConfiguration()
        {
            Grid grid = new Grid();
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());

            Label l = new Label() { Content = "Mode: " };
            grid.Children.Add(l);
            Grid.SetRow(l, 0);
            Grid.SetColumn(l, 0);

            // Combobox
            ComboBox combo = new ComboBox() { VerticalAlignment = VerticalAlignment.Center };
            combo.SetBinding(ComboBox.SelectedItemProperty, new Binding("SelectedMode"));

            // Combo percentage mode
            Grid modeGrid = new Grid();
            modeGrid.ColumnDefinitions.Add(new ColumnDefinition());
            modeGrid.ColumnDefinitions.Add(new ColumnDefinition());

            Mode percentageMode = new Mode() { Name = "Percentage", RankMode = RankSelector.SelectionMode.Percentage };

            l = new Label() { Content = "Percentage:" };
            modeGrid.Children.Add(l);
            Grid.SetColumn(l, 0);

            TextBox tb = new TextBox() { VerticalAlignment = VerticalAlignment.Center };
            tb.SetBinding(TextBox.TextProperty, new Binding("Percentage"));
            modeGrid.Children.Add(tb);
            Grid.SetColumn(tb, 1);

            percentageMode.ModeGUI = modeGrid;

            // Number mode
            modeGrid = new Grid();
            modeGrid.ColumnDefinitions.Add(new ColumnDefinition());
            modeGrid.ColumnDefinitions.Add(new ColumnDefinition());

            Mode numberMode = new Mode() { Name = "Best N", RankMode = RankSelector.SelectionMode.Number };

            l = new Label() { Content = "N:" };
            modeGrid.Children.Add(l);
            Grid.SetColumn(l, 0);

            tb = new TextBox() { VerticalAlignment = VerticalAlignment.Center };
            tb.SetBinding(TextBox.TextProperty, new Binding("Number"));
            modeGrid.Children.Add(tb);
            Grid.SetColumn(tb, 1);

            numberMode.ModeGUI = modeGrid;

            combo.ItemsSource = new ObservableCollection<Mode>() { percentageMode, numberMode };

            grid.Children.Add(combo);
            Grid.SetRow(combo, 0);
            Grid.SetColumn(combo, 1);

            ContentControl c = new ContentControl();
            c.SetBinding(ContentControl.ContentProperty, new Binding("SelectedMode.ModeGUI"));

            grid.Children.Add(c);
            Grid.SetRow(c, 1);
            Grid.SetColumn(c, 0);
            Grid.SetColumnSpan(c, 2);

            return grid;
        }
开发者ID:OlekNg,项目名称:AHMED,代码行数:69,代码来源:RankSelectionConfiguration.cs


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