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


C# DataTemplate.LoadContent方法代码示例

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


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

示例1: 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

示例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: 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

示例4: DataTemplateElement

        /// <summary>
        /// Initializes a new instance of the <see cref="DataTemplateElement"/> class.
        /// </summary>
        /// <param name="dataTemplate">The data template.</param>
        /// <param name="boundType">Type of the bound.</param>
        /// <param name="baseName">Name of the base.</param>
        internal DataTemplateElement(DataTemplate dataTemplate, BoundType boundType, string baseName)
            : base(dataTemplate.LoadContent(), boundType)
        {
            _dataTemplate = dataTemplate;

            if(_dataTemplate.DataTemplateKey != null)
                BaseName = baseName + " [DataTemplate " + _dataTemplate.DataTemplateKey + "] ";

            else BaseName = baseName + " [DataTemplate] ";
        }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:16,代码来源:DataTemplateElement.cs

示例5: PrintTable

 public PrintTable(DataTemplate itemsControlTemplate, IEnumerable itemsSource, PrintTemplate columnsHeader, PrintTemplate tableHeader, PrintTemplate tableFooter, Border border, PrintTemplate caption)
 {
     var control = (ItemsControl) itemsControlTemplate.LoadContent();
     this.itemTemplate = control.ItemTemplate;
     this.itemsSource = itemsSource;
     this.itemsControlTemplate = itemsControlTemplate;
     this.tableFooter = tableFooter;
     this.tableHeader = tableHeader;
     this.columsHeader = columnsHeader;
     this.border = border;
     this.caption = caption;
 }
开发者ID:schakko,项目名称:bootstrap-net,代码行数:12,代码来源:PrintTable.cs

示例6: PrintPage

        //, double headerHeight, double footerHeight)
        public PrintPage(PrintLayout pageLayout, Size bodySize, DataTemplate headerTemplate, DataTemplate footerTemplate)
        {
            InitializeComponent();
            ChildRenderTransform = pageLayout.RenderTransform;
            BodySize = bodySize; //new Size(pageLayout.ContentSize.Width, pageLayout.ContentSize.Height - footerHeight - headerHeight);
            Height = pageLayout.Size.Height - pageLayout.Margin.Bottom - pageLayout.Margin.Top;
            Width = pageLayout.Size.Width - pageLayout.Margin.Left - pageLayout.Margin.Right;
            Margin = pageLayout.Margin;

            if (headerTemplate != null)
            {
                this.Header.Children.Add((UIElement) headerTemplate.LoadContent());
            }
            if (footerTemplate != null)
            {
                this.Footer.Children.Add((UIElement) footerTemplate.LoadContent());
            }
        }
开发者ID:schakko,项目名称:bootstrap-net,代码行数:19,代码来源:PrintPage.xaml.cs

示例7: GetTemplatedCell

 private UIElement GetTemplatedCell(C1FlexGrid grid, DataTemplate dt)
 {
     if (_cacheOwner == null)
     {
         _cacheOwner = grid;
     }
     List<UIElement> list = null;
     if (ReferenceEquals(grid, _cacheOwner) && _dtCache.TryGetValue(dt, out list) && list.Count > 0)
     {
         foreach (UIElement current in list)
         {
             if (VisualTreeHelper.GetParent(current) == null)
             {
                 return current;
             }
         }
     }
     UIElement uiElement = dt.LoadContent() as UIElement;
     if (uiElement != null && ReferenceEquals(grid, _cacheOwner))
     {
         if (list == null)
         {
             list = new List<UIElement>();
             _dtCache[dt] = list;
         }
         list.Add(uiElement);
         _dtRawCache[uiElement] = true;
     }
     return uiElement;
 }
开发者ID:mdjabirov,项目名称:C1Decompiled,代码行数:30,代码来源:CellFactory.cs

示例8: CreateTemplateControl

 /// <summary>
 /// Creates the template control.
 /// </summary>
 /// <param name="d">The definition.</param>
 /// <param name="template">The data template.</param>
 /// <returns>A content control.</returns>
 protected virtual FrameworkElement CreateTemplateControl(TemplateCellDefinition d, DataTemplate template)
 {
     var content = (FrameworkElement)template.LoadContent();
     var binding = this.CreateBinding(d);
     binding.Mode = BindingMode.OneWay;
     var c = new ContentControl
     {
         HorizontalAlignment = HorizontalAlignment.Stretch,
         VerticalAlignment = VerticalAlignment.Stretch,
         Content = content
     };
     content.SetBinding(FrameworkElement.DataContextProperty, binding);
     this.SetIsEnabledBinding(d, content);
     this.SetBackgroundBinding(d, c);
     return c;
 }
开发者ID:Mitch-Connor,项目名称:PropertyTools,代码行数:22,代码来源:DataGridControlFactory.cs

示例9: Create

 public static FrameworkElement Create(DataTemplate template, object dataContext)
 {
     var element = (FrameworkElement) template.LoadContent();
     element.DataContext = dataContext;
     return element;
 }
开发者ID:schakko,项目名称:bootstrap-net,代码行数:6,代码来源:PrintTemplate.cs

示例10: OnContentTemplateChanged

 protected virtual void OnContentTemplateChanged(DataTemplate oldContentTemplate, DataTemplate newContentTemplate)
 {
     if (this.contentTemplateInstance != null)
     {
         this.contentTemplateInstance.LayoutUpdated -= this.ContentControl_LayoutUpdated;
         this.RemoveContentTemplateInstance();
         this.RemoveLogicalChild(this.contentTemplateInstance);
     }
     if (newContentTemplate != null)
     {
         this.contentTemplateInstance = (UIElement)newContentTemplate.LoadContent();
         this.contentTemplateInstance.LayoutUpdated += this.ContentControl_LayoutUpdated;
         this.AddLogicalChild(this.contentTemplateInstance);
         if (this.Content is UIElement)
         {
             this.NativeChangeUIContentParent();
         }
         this.contentTemplateInstance.DataContext = this.Content;
         this.AddContentTemplateInstance();
     }
     else
     {
         if (this.Content is UIElement)
         {
             this.NativeChangeUIContentParent();
         }
         this.contentTemplateInstance = null;
     }
     this.OnNativeContentChanged(null, this.Content);
     this.OnLayoutUpdated();
 }
开发者ID:evnik,项目名称:UIFramework,代码行数:31,代码来源:ContentControl.cs

示例11: LoadDataTemplate

        /// <summary>
        /// Loads the data template.
        /// </summary>
        /// <param name="dataTemplate">The data template.</param>
        /// <returns>List{FrameworkContentElement}.</returns>
        public static List<FrameworkContentElement> LoadDataTemplate(DataTemplate dataTemplate)
        {
            var elements = new List<FrameworkContentElement>();

            var documentDataTemplate = dataTemplate as DocumentDataTemplate;
            DependencyObject content;
            if (documentDataTemplate != null)
                content = documentDataTemplate.LoadDocumentTemplate();
            else 
                content = dataTemplate.LoadContent();

            var sp = content as StackPanel;
            if (sp != null)
                foreach (var child in sp.Children)
                {
                    var childDependencyObject = child as DependencyObject;
                    if (childDependencyObject != null)
                        elements.AddRange(ProcessDataTemplateItems(childDependencyObject));
                }
            else 
                elements.AddRange(ProcessDataTemplateItems(content));
            return elements;
        }
开发者ID:sat1582,项目名称:CODEFramework,代码行数:28,代码来源:RepeatingSection.cs

示例12: CreateItem

        private ListViewItem CreateItem(object dataItem, int index, DataTemplate itemTemplate, Style itemContainerStyle)
        {
            FrameworkElement uiItem = itemTemplate.LoadContent() as FrameworkElement;
            if (uiItem != null) {
                ListViewItem item = new ListViewItem();
                if (itemContainerStyle != null) {
                    item.Style = itemContainerStyle;
                }
                item.DataContext = dataItem;
                item.Content = uiItem;

                _items.Insert(index, item);
                _itemMap[dataItem] = item;

                return item;
            }

            return null;
        }
开发者ID:nikhilk,项目名称:silverlightfx,代码行数:19,代码来源:ListView.cs


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