• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Windows.DataTemplate类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: CreateCellTemplate

        internal static System.Windows.DataTemplate CreateCellTemplate(EntityFieldInfo entityFieldInfo,DataGrid dataGrid)
        {
            DataTemplate dataTemplate = new DataTemplate();
            FrameworkElementFactory contentControl = new FrameworkElementFactory(typeof(ContentControl));
            contentControl.SetBinding(ContentControl.ContentProperty, new Binding());
            Style contentControlStyle = new Style();
            contentControl.SetValue(ContentControl.StyleProperty, contentControlStyle);

            DataTemplate tpl = new DataTemplate();
            if (entityFieldInfo.ControlType == Infrastructure.Attributes.ControlType.Color)
            {
                FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid));
                Binding binding = CreateBindingOneWay(entityFieldInfo.Path);
                binding.Converter = new StringToBrushConverter();
                grid.SetBinding(Grid.BackgroundProperty, binding);
                tpl.VisualTree = grid;
                contentControlStyle.Setters.Add(new Setter(ContentControl.ContentTemplateProperty, tpl));
                dataTemplate.VisualTree = contentControl;
            }
            else
            {
                FrameworkElementFactory textBox = new FrameworkElementFactory(typeof(TextBlock));
                if (entityFieldInfo.ControlType == Infrastructure.Attributes.ControlType.Pr)
                { textBox.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right); }
                textBox.SetBinding(TextBlock.TextProperty, CreateBindingOneWay(entityFieldInfo.Path));
                tpl.VisualTree = textBox;
                contentControlStyle.Setters.Add(new Setter(ContentControl.ContentTemplateProperty, tpl));
                dataTemplate.VisualTree = contentControl;
            }

            return dataTemplate;
        }
开发者ID:ChampsyGnom,项目名称:GeoPat,代码行数:32,代码来源:DataGridTemplateBuilder.cs


示例17: ChangeIsDeleted

		void ChangeIsDeleted()
		{
			if (_deletationType == LogicalDeletationType.All)
			{
				if (!IsColumnShown)
				{
					var gridViewColumn = new GridViewColumn();
					gridViewColumn.Header = "Дата удаления";
					gridViewColumn.Width = 150;
					var dataTemplate = new DataTemplate();
					var txtElement = new FrameworkElementFactory(typeof(IsDeletedTextBlock));
					dataTemplate.VisualTree = txtElement;
					var binding = new Binding();
					var bindingPath = string.Format("RemovalDate");
					binding.Path = new PropertyPath(bindingPath);
					binding.Mode = BindingMode.OneWay;
					txtElement.SetBinding(IsDeletedTextBlock.TextProperty, binding);
					gridViewColumn.CellTemplate = dataTemplate;
					ListViewLayoutManager.SetCanUserResize(gridViewColumn, false);
					gridView.Columns.Add(gridViewColumn);
				}
			}
			else if (IsColumnShown)
			{
				gridView.Columns.Remove(IsDeletedColumn);
			}
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:27,代码来源:ChangeIsDeletedViewSubscriber.cs


示例18: GetNewMessagesNotificationOverlay

		public static ImageSource GetNewMessagesNotificationOverlay(Window window, DataTemplate template, int count = 0)
		{
			if (window == null)
				return null;

			var presentation = PresentationSource.FromVisual(window);
			if (presentation == null)
				return null;
			Matrix m = presentation.CompositionTarget.TransformToDevice;
			double dx = m.M11;
			double dy = m.M22;

			double iconWidth = 16.0 * dx;
			double iconHeight = 16.0 * dy;

			string countText = count.ToString();

			RenderTargetBitmap bmp = new RenderTargetBitmap((int) iconWidth, (int) iconHeight, 96, 96, PixelFormats.Default);

			ContentControl root = new ContentControl
			{
				ContentTemplate = template,
				Content = count > 99 ? "…" : countText
			};

			root.Arrange(new Rect(0, 0, iconWidth, iconHeight));

			bmp.Render(root);

			return bmp;
		}
开发者ID:kveretennicov,项目名称:kato,代码行数:31,代码来源:Taskbarhelper.cs


示例19: UpdateAdditionalColumns

		void UpdateAdditionalColumns()
		{
			GridView gridView = _treeList.View as GridView;
			EmployeesViewModel employeesViewModel = _treeList.DataContext as EmployeesViewModel;
			if (employeesViewModel.AdditionalColumnNames == null)
				return;

			var columnCount = 2;
			for (int i = gridView.Columns.Count - 1; i >= columnCount; i--)
			{
				gridView.Columns.RemoveAt(i);
			}

			for (int i = 0; i < employeesViewModel.AdditionalColumnNames.Count; i++)
			{
				var gridViewColumn = new GridViewColumn();
				gridViewColumn.Header = employeesViewModel.AdditionalColumnNames[i];
				gridViewColumn.Width = 350;

				var dataTemplate = new DataTemplate();
				var txtElement = new FrameworkElementFactory(typeof(TextBlock));
				dataTemplate.VisualTree = txtElement;
				var binding = new Binding();
				var bindingPath = string.Format("AdditionalColumnValues[{0}]", i);
				binding.Path = new PropertyPath(bindingPath);
				binding.Mode = BindingMode.OneWay;
				txtElement.SetBinding(TextBlock.TextProperty, binding);
				ListViewLayoutManager.SetStarWidth(gridViewColumn, 5);
				gridViewColumn.CellTemplate = dataTemplate;
				gridView.Columns.Add(gridViewColumn);
			}
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:32,代码来源:EmployeesView.xaml.cs


示例20: DataTemplateAdorner

		public DataTemplateAdorner(object data, UIElement adornedElement, DataTemplate dataTemplate)
			: base(adornedElement) {
			_contentPresenter = new ContentPresenter() {
				Content = data,
				ContentTemplate = dataTemplate,
			};
		}
开发者ID:RushuiGuan,项目名称:mvvm,代码行数:7,代码来源:DataTemplateAdorner.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Windows.DependencyObject类代码示例发布时间:2022-05-26
下一篇:
C# Windows.DataObjectPastingEventArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap