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


C# Windows.DataTemplate类代码示例

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


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

示例1: CreateItemTemplate

        private DataTemplate CreateItemTemplate()
        {
            var template = new DataTemplate();

            template.VisualTree = new FrameworkElementFactory(typeof(StackPanel));

            var txtBlock = new FrameworkElementFactory(typeof(TextBlock));
            txtBlock.SetBinding(TextBlock.TextProperty, new Binding("Street1")); 
            template.VisualTree.AppendChild(txtBlock);

            txtBlock = new FrameworkElementFactory(typeof(TextBlock));
            txtBlock.SetBinding(TextBlock.TextProperty, new Binding("City")); 
            template.VisualTree.AppendChild(txtBlock);

            var trigger = new MultiDataTrigger();

            trigger.Conditions.Add(
                new Condition(
                    new Binding("Cty"), //misspelling
                    "Tallahassee"
                    )
                );

            trigger.Conditions.Add(
                new Condition(
                    new Binding("StateOrProvince"),
                    "Florida"
                    )
                );

            template.Triggers.Add(trigger);

            return template;
        }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:34,代码来源:UIBoundToCustomerWithContentControlAndMultiTriggers.cs

示例2: LoadContent

        /// <summary>
        /// Loads content in the specified template.
        /// </summary>
        /// <param name="template">Template to load.</param>
        /// <returns>Contents loaded from the specified template.</returns>
        public static DependencyObject LoadContent(DataTemplate template)
        {
            // This is a work around for a Beta1 Bug
            // Where under load the LoadContent can fail.
            // This stops us seeing this issue as frequently.
            // The idea is to try upto 5 times to load a template.
            // If it still does not load then rethrow the exception.
            int retryCount = 5;
            DependencyObject dependencyObject = null;
            if (template != null)
            {
                while (null == dependencyObject && 0 != retryCount)
                {
                    try
                    {
                        dependencyObject = template.LoadContent();
                    }
                    catch (System.Windows.Markup.XamlParseException e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.ToString());
                        System.Diagnostics.Debug.WriteLine("\n Template Load Error");
                        retryCount--;
                        System.Threading.Thread.SpinWait(2000);
                        if (retryCount == 0)
                        {
                            throw;
                        }
                    }
                }
            }

            return dependencyObject;
        }
开发者ID:rbirkby,项目名称:mscui,代码行数:38,代码来源:DataTemplateHelper.cs

示例3: SelectTemplate

			public override DataTemplate SelectTemplate(object item, DependencyObject container)
			{
				NGTreeNode node = item as NGTreeNode;
				if (node != null)
				{
					if (node.Tag is NamedColor)
					{
						if (null == _namedColorTemplate)
							_namedColorTemplate = (DataTemplate)_parent.TryFindResource("NamedColorTemplate");
						if (null != _namedColorTemplate)
							return _namedColorTemplate;
					}
					else if (node.Tag is IColorSet)
					{
						if (null == _colorSetTemplate)
							_colorSetTemplate = (DataTemplate)_parent.TryFindResource("ColorSetTemplate");
						if (null != _colorSetTemplate)
							return _colorSetTemplate;
					}
					else
					{
						if (null == _treeOtherTemplate)
							_treeOtherTemplate = (DataTemplate)_parent.TryFindResource("TreeOtherTemplate");
						if (null != _treeOtherTemplate)
							return _treeOtherTemplate;
					}
				}

				return base.SelectTemplate(item, container);
			}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:30,代码来源:ColorSetIdentifierControl.xaml.cs

示例4: ListViewSorter

 public ListViewSorter(ListView listView, DefaultHeaderSortDirections defaultHeaderSortDirections, DataTemplate upArrow, DataTemplate downArrow)
 {
     this.listView = listView;
     this.defaultHeaderSortDirections = defaultHeaderSortDirections;
     this.upArrow = upArrow;
     this.downArrow = downArrow;
 }
开发者ID:Jamedjo,项目名称:Raticon,代码行数:7,代码来源:ListViewSorter.cs

示例5: PropertyValueDialogControl

        // <summary>
        // Basic ctor
        // </summary>
        // <param name="property">Property to display</param>
        // <param name="valueDialogTemplate">Template to use</param>
        public PropertyValueDialogControl(PropertyEntry property, DataTemplate valueDialogTemplate) 
        {
            Fx.Assert(property != null, "property parameter is null");
            Fx.Assert(valueDialogTemplate != null, "valueDialogTemplate parameter is null");

            ModelPropertyEntry modelPropertyValue = property as ModelPropertyEntry;
            if (modelPropertyValue != null) 
            {
                _rootTransaction = modelPropertyValue.FirstModelProperty.Value.BeginEdit();
            }

            InitializeComponent();

            // Make sure we use PI-specific resources within this control
            this.Resources.MergedDictionaries.Add(PropertyInspectorResources.GetResources());

            // Hook into an opening of nested dialogs.  PropertyInspector class takes care of this for us.
            // However, we are using Blend's collection editor which doesn't do the same thing, so
            // we need to reproduce that behavior manually.
            PropertyValueDialogHost.AttachOpenDialogHandlers(this);

            // Hook into the standard set of Commands
            _defaultCommandHandler = new PropertyValueEditorCommandHandler(this);


            _OKButton.Click += new RoutedEventHandler(OnOkButtonClicked);
            _cancelButton.Click += new RoutedEventHandler(OnCancelButtonClicked);
            _contentControl.Content = property.PropertyValue;
            _contentControl.ContentTemplate = valueDialogTemplate;

            //Handle the commit and cancel keys within the property inspector, that is hosted in the collection editor
            ValueEditorUtils.SetHandlesCommitKeys(this, true);

        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:39,代码来源:PropertyValueDialogControl.xaml.cs

示例6: EditableTextBlock

		public EditableTextBlock()
		{
			var textBox = new FrameworkElementFactory(typeof(TextBox));
			textBox.SetValue(Control.PaddingProperty, new Thickness(1)); // 1px for border
			textBox.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(TextBox_Loaded));
			textBox.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
			textBox.AddHandler(UIElement.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
			textBox.SetBinding(TextBox.TextProperty, new System.Windows.Data.Binding("Text") { Source = this, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
			var editTemplate = new DataTemplate { VisualTree = textBox };

			var textBlock = new FrameworkElementFactory(typeof(TextBlock));
			textBlock.SetValue(FrameworkElement.MarginProperty, new Thickness(2));
			textBlock.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(TextBlock_MouseDown));
			textBlock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding("Text") { Source = this });
			var viewTemplate = new DataTemplate { VisualTree = textBlock };

			var style = new System.Windows.Style(typeof(EditableTextBlock));
			var trigger = new Trigger { Property = IsInEditModeProperty, Value = true };
			trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = editTemplate });
			style.Triggers.Add(trigger);

			trigger = new Trigger { Property = IsInEditModeProperty, Value = false };
			trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = viewTemplate });
			style.Triggers.Add(trigger);
			Style = style;
		}
开发者ID:alexandrebaker,项目名称:Eto,代码行数:26,代码来源:EditableTextBlock.cs

示例7: TryFindDataTemplate

 protected abstract bool TryFindDataTemplate(
     ResourceDictionary resources, 
     FrameworkElement resourcesOwner,
     DependencyObject itemContainer,
     object item, 
     Type itemType,
     out DataTemplate dataTemplate);
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:7,代码来源:ResourcesTraversingDataTemplateSelector.cs

示例8: LoadDataTemplate

        public static FrameworkContentElement LoadDataTemplate(DataTemplate dataTemplate)
        {
            var content = dataTemplate.LoadContent();
            if (content is Fragment)
            {
                return ((Fragment)content).Content;
            }
            else if (content is TextBlock)
            {
                var inlines = ((TextBlock)content).Inlines;
                if (inlines.Count == 1)
                    return inlines.FirstInline;
                else
                {
                    var paragraph = new Paragraph();
                    // we can't use an enumerator, since adding an inline removes it from its collection
                    while (inlines.FirstInline != null)
                        paragraph.Inlines.Add(inlines.FirstInline);

                    return paragraph;
                }
            }
            else
            {
                throw new Exception("Data template needs to contain a <Fragment> or <TextBlock>");
            }
        }
开发者ID:Konctantin,项目名称:SpellWork,代码行数:27,代码来源:Helpers.cs

示例9: TrySelectTemplate

            public bool TrySelectTemplate(
                object item,
                DependencyObject container,
                string context,
                bool isTooltip,
                out DataTemplate dataTemplate)
            {
                dataTemplate = null;

                if (DataTemplateProvider == null)
                    return false;

                if (item == null)
                    return false;

                var cached_item = (object)null;

                if(Item.TryGetTarget(out cached_item))
                {
                    if (cached_item == null)
                        return false;

                    if (cached_item.GetType() != item.GetType())
                        return false;
                }

                if (!string.Equals(Context, context))
                    return false;

                return DataTemplateProvider.TrySelectTemplate(item, container, context, isTooltip, out dataTemplate);
            }
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:31,代码来源:ContextAwareDataTemplateSelectorService.Cache.cs

示例10: LoadDataTemplate

        internal static FrameworkContentElement LoadDataTemplate(DataTemplate dataTemplate)
        {
            object content = dataTemplate.LoadContent();

            if (content is Fragment)
            {
                return (FrameworkContentElement)((Fragment)content).Content;
            }
            else if (content is TextBlock)
            {
                InlineCollection inlines = ((TextBlock)content).Inlines;

                if (inlines.Count == 1)
                {
                    return inlines.FirstInline;
                }
                else
                {
                    Paragraph paragraph = new Paragraph();

                    while (inlines.FirstInline != null)
                    {
                        paragraph.Inlines.Add(inlines.FirstInline);
                    }

                    return paragraph;
                }
            }
            else
            {
                throw new Exception("Data template needs to contain a <Fragment> or <TextBlock>");
            }
        }
开发者ID:rodrigovedovato,项目名称:FlowDocumentReporting,代码行数:33,代码来源:Helpers.cs

示例11: AddDataTemplate

 private void AddDataTemplate(Type viewType, Type viewModelType)
 {
     var dataTemplate = new DataTemplate(viewModelType);
     dataTemplate.VisualTree = new FrameworkElementFactory(viewType);
     dataTemplate.Seal();
     App.Current.Resources.Add(new DataTemplateKey(viewModelType), dataTemplate);
 }
开发者ID:NicolasDorier,项目名称:GestSpace,代码行数:7,代码来源:App.xaml.cs

示例12: SelectTemplate

 public override DataTemplate SelectTemplate(object item, DependencyObject container)
 {
     DataTemplate tmp = this.Template1;
     this.Template1 = this.Template2;
     this.Template2 = tmp;
     return tmp;
 }
开发者ID:jigjosh,项目名称:xaml-sdk,代码行数:7,代码来源:BinaryTemplateSelector.cs

示例13: CreateDefaultTemplate

 internal static DataTemplate CreateDefaultTemplate()
 {
     var dataTemplate = new DataTemplate();
     var factory = new FrameworkElementFactory(typeof(ContentPresenter));
     dataTemplate.VisualTree = factory;
     return dataTemplate;
 }
开发者ID:gitter-badger,项目名称:Gu.Wpf.DataGrid2D,代码行数:7,代码来源:Helpers.cs

示例14: KernelOnComponentRegistered

        private void KernelOnComponentRegistered(string key, IHandler handler)
        {
            Type implementation = handler.ComponentModel.Implementation;
            if (implementation.Namespace == null ||
                !implementation.Namespace.EndsWith("ViewModels"))
            {
                return;
            }

            var viewTypeName = implementation.Namespace.Replace("ViewModels", "Views") + "." +
                                implementation.Name.Replace("ViewModel", "View");

            var qualifiedViewTypeName = implementation.AssemblyQualifiedName.Replace(implementation.FullName, viewTypeName);

            Type viewType = Type.GetType(qualifiedViewTypeName, false);
            if (viewType == null)
            {
                throw new InvalidOperationException();
            }

            var dt = new DataTemplate {DataType = viewType};

            var viewFactory = new FrameworkElementFactory(viewType);
            dt.VisualTree = viewFactory;

            _resources.Add(new DataTemplateKey(implementation), dt);
        }
开发者ID:ArildF,项目名称:Core,代码行数:27,代码来源:ViewModelRegistrationFacility.cs

示例15: ListColorsEvenElegantlier

        public ListColorsEvenElegantlier()
        {
            Title = "List Colors Even Elegantlier";

            DataTemplate template = new DataTemplate(typeof(NamedBrush));
            FrameworkElementFactory factoryStack = new FrameworkElementFactory(typeof(StackPanel));
            factoryStack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            template.VisualTree = factoryStack;

            FrameworkElementFactory factoryRectangle = new FrameworkElementFactory(typeof(Rectangle));
            factoryRectangle.SetValue(Rectangle.WidthProperty, 16.0);
            factoryRectangle.SetValue(Rectangle.HeightProperty, 16.0);
            factoryRectangle.SetValue(Rectangle.MarginProperty, new Thickness(2));
            factoryRectangle.SetValue(Rectangle.StrokeProperty, SystemColors.WindowTextBrush);
            factoryRectangle.SetBinding(Rectangle.FillProperty, new Binding("Brush"));
            factoryStack.AppendChild(factoryRectangle);

            FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock));
            factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            factoryTextBlock.SetValue(TextBlock.TextProperty, new Binding("Name"));
            factoryStack.AppendChild(factoryTextBlock);

            ListBox lstbox = new ListBox();
            lstbox.Width = 150;
            lstbox.Height = 150;
            Content = lstbox;

            lstbox.ItemTemplate = template;
            lstbox.ItemsSource = NamedBrush.All;

            lstbox.SelectedValuePath = "Brush";
            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
            lstbox.DataContext = this;
        }
开发者ID:JianchengZh,项目名称:kasicass,代码行数:34,代码来源:ListColorsEvenElegantlier.cs


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