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


C# ItemsControl.SetBinding方法代码示例

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


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

示例1: ControlWithExistingBindingOnItemsSourceWithNullValueThrows

        public void ControlWithExistingBindingOnItemsSourceWithNullValueThrows()
        {
            var control = new ItemsControl();
            Binding binding = new Binding("Enumerable");
            binding.Source = new SimpleModel() { Enumerable = null };
            control.SetBinding(ItemsControl.ItemsSourceProperty, binding);

            IRegionAdapter adapter = new TestableItemsControlRegionAdapter();

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

示例2: CreateCheckableItems

        /// <summary>
        /// Creates a sequence of checkboxes.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// A FrameworkElement.
        /// </returns>
        protected virtual FrameworkElement CreateCheckableItems(PropertyItem property)
        {
            var lb = new ItemsControl();
            var rectangleFactory = new FrameworkElementFactory(typeof(CheckBox));
            rectangleFactory.SetBinding(ToggleButton.IsCheckedProperty, new Binding(property.CheckableItemsIsCheckedPropertyName));
            rectangleFactory.SetBinding(ContentControl.ContentProperty, new Binding(property.CheckableItemsContentPropertyName));

            lb.ItemTemplate = new DataTemplate { VisualTree = rectangleFactory };
            lb.SetBinding(ItemsControl.ItemsSourceProperty, property.CreateBinding());
            lb.Margin = new Thickness(0, 6, 0, 6);

            return lb;
        }
开发者ID:hasol81,项目名称:PropertyTools,代码行数:20,代码来源:DefaultPropertyControlFactory.cs

示例3: PluginBase

        public PluginBase()
        {
            // Any inputs the plugin may have
            Inputs = new ObservableDictionary<string, InputSignalViewModel>();

            // Create style resources with the correct 5px margin
            Style ButtonStyle = new Style(typeof(Button), (Style)FindResource(typeof(Button)));
            ButtonStyle.Setters.Add(new Setter(Button.MarginProperty, new Thickness(5)));
            // StackPanel that holds our signal sources
            OutputsStackPanel = new StackPanel();

            // "Signal Source Mapping" title textblock
            TextBlock signalSourceViewTitle = new TextBlock();
            signalSourceViewTitle.Text = "Signal Output Mapping";
            signalSourceViewTitle.Style = (Style)Application.Current.Resources["Title"];
            OutputsStackPanel.Children.Add(signalSourceViewTitle);

            // ObservableDictionary to hold all of the signal sources that our plugin might have
            Outputs = new ObservableDictionary<string, OutputSignalViewModel>();

            // GUI element to display all of the items properly using a SignalSourceView
            ItemsControl SignalSourceControl = new ItemsControl();
            DataTemplate signalDataTemplate = CreateTemplate(typeof(OutputSignalViewModel), typeof(SignalSourceView));
            var key = signalDataTemplate.DataTemplateKey;
            if(Application.Current.Resources[key] == null)
                Application.Current.Resources.Add(key, signalDataTemplate);
            SignalSourceControl.SetBinding(ItemsControl.ItemsSourceProperty, "Outputs.Values");
            OutputsStackPanel.Children.Add(SignalSourceControl);

            // Set the plugin datacontext to itself -- we assume we're not doing separate view models.
            this.DataContext = this;
            MainArea = new StackPanel();
            SetCurrentValue(PluginContentProperty, new StackPanel());

            // [Plugin Name] Configuration title textblock
            TextBlock title = new TextBlock();
            title.SetBinding(TextBlock.TextProperty, "DisplayTitle");
            title.Style = (Style)Application.Current.Resources["Title"];

            ModernButton infoButton = new ModernButton();
            var streamGeometry = StreamGeometry.Parse("F1 M 38,19C 48.4934,19 57,27.5066 57,38C 57,48.4934 48.4934,57 38,57C 27.5066,57 19,48.4934 19,38C 19,27.5066 27.5066,19 38,19 Z M 33.25,33.25L 33.25,36.4167L 36.4166,36.4167L 36.4166,47.5L 33.25,47.5L 33.25,50.6667L 44.3333,50.6667L 44.3333,47.5L 41.1666,47.5L 41.1666,36.4167L 41.1666,33.25L 33.25,33.25 Z M 38.7917,25.3333C 37.48,25.3333 36.4167,26.3967 36.4167,27.7083C 36.4167,29.02 37.48,30.0833 38.7917,30.0833C 40.1033,30.0833 41.1667,29.02 41.1667,27.7083C 41.1667,26.3967 40.1033,25.3333 38.7917,25.3333 Z ");
            infoButton.IconData = streamGeometry;
            infoButton.Command = ToggleInfoCommand;

            InfoTextBlock = new TextBlock();
            //InfoTextBlock.SetBinding(TextBox.TextProperty, "InfoString");
            //            InfoTextBlock.Text = "Info...";
            InfoTextBlock.Visibility = Visibility.Collapsed;
            InfoTextBlock.TextWrapping = TextWrapping.Wrap;
            Binding infoBinding = new Binding();
            infoBinding.Path = new PropertyPath("InfoString");
            BindingOperations.SetBinding(InfoTextBlock, TextBlock.TextProperty, infoBinding);

            UniformGrid grid1 = new UniformGrid();
            grid1.Columns = 2;
            grid1.Children.Add(title);
            grid1.Children.Add(infoButton);

            // Instance name GUI stuff
            UniformGrid grid2 = new UniformGrid();
            TextBlock InstanceNameLabel = new TextBlock();
            InstanceNameLabel.Text = "Instance Name";
            TextBox InstanceNameBox = new TextBox();
            Binding binding = new Binding();
            binding.Path = new PropertyPath("InstanceName");
            InstanceNameBox.SetBinding(TextBox.TextProperty, binding);
            grid2.Columns = 2;
            grid2.Children.Add(InstanceNameLabel);
            grid2.Children.Add(InstanceNameBox);
            MainArea.Children.Add(grid1);
            MainArea.Children.Add(InfoTextBlock);
            MainArea.Children.Add(grid2);

            this.Initialized += PluginBase_Initialized;
        }
开发者ID:surgical-robots,项目名称:robot-control-app,代码行数:75,代码来源:PluginBase.cs


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