定义模版选择器
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace Deedy.Activity
|
||||||
|
{
|
||||||
|
public class ActionTemplateCollection : ObservableCollection<DataTemplate>
|
||||||
|
{
|
||||||
|
public ActionTemplateCollection() { }
|
||||||
|
public bool TryGetTemplate(Type type, out DataTemplate template)
|
||||||
|
{
|
||||||
|
DataTemplate dataTemplate = new DataTemplate(typeof(IActionElement));
|
||||||
|
bool result = false;
|
||||||
|
foreach (var item in this)
|
||||||
|
{
|
||||||
|
if (type.Equals(item.DataType))
|
||||||
|
{
|
||||||
|
dataTemplate = item;
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template = dataTemplate;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Markup;
|
||||||
|
|
||||||
|
namespace Deedy.Activity
|
||||||
|
{
|
||||||
|
[ContentProperty("ActionTemplates")]
|
||||||
|
[Localizability(LocalizationCategory.Ignore)]
|
||||||
|
public class ActionTemplateSelector : DataTemplateSelector
|
||||||
|
{
|
||||||
|
[AllowNull]
|
||||||
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
|
||||||
|
public ActionTemplateCollection ActionTemplates { get; internal set; } = new ActionTemplateCollection();
|
||||||
|
[AllowNull]
|
||||||
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||||
|
public Uri Source { get; set; }
|
||||||
|
|
||||||
|
private bool IsLoaded = false;
|
||||||
|
private void LoadFromSource()
|
||||||
|
{
|
||||||
|
if (IsLoaded || Source == null) return;
|
||||||
|
//TODO:从Source中加载DataTemplate;要求DataType必须继承IActionElement接口(ActionTemplates中设置的模版高于Source中的模版)
|
||||||
|
IsLoaded = true;
|
||||||
|
}
|
||||||
|
public ActionTemplateSelector() { }
|
||||||
|
public override DataTemplate SelectTemplate(object item, DependencyObject container)
|
||||||
|
{
|
||||||
|
this.LoadFromSource();
|
||||||
|
|
||||||
|
return base.SelectTemplate(item, container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
4
DeedyDesigner/Deedy.Activity/Themes/FlowTemplates.xaml
Normal file
4
DeedyDesigner/Deedy.Activity/Themes/FlowTemplates.xaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
|
|
||||||
|
</ResourceDictionary>
|
||||||
9
DeedyDesigner/Deedy.Activity/Themes/FuncTemplates.xaml
Normal file
9
DeedyDesigner/Deedy.Activity/Themes/FuncTemplates.xaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:Deedy.Activity">
|
||||||
|
<local:ActionTemplateSelector x:Key="AuxTemplateSelector">
|
||||||
|
<DataTemplate DataType="{x:Type local:BasalAction}">
|
||||||
|
|
||||||
|
</DataTemplate>
|
||||||
|
</local:ActionTemplateSelector>
|
||||||
|
</ResourceDictionary>
|
||||||
Reference in New Issue
Block a user