|
|
|
@ -11,35 +11,30 @@ namespace Perspex.Markup.Xaml.Templates |
|
|
|
[ContentProperty("Content")] |
|
|
|
public class DataTemplate : IDataTemplate |
|
|
|
{ |
|
|
|
private bool MyMatch(object data) |
|
|
|
public Type DataType { get; set; } |
|
|
|
|
|
|
|
public TemplateContent Content { get; set; } |
|
|
|
|
|
|
|
public bool Match(object data) |
|
|
|
{ |
|
|
|
if (DataType == null) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("XAML DataTemplates must have a DataType"); |
|
|
|
throw new InvalidOperationException("DataTemplate must have a DataType."); |
|
|
|
} |
|
|
|
|
|
|
|
return DataType == data.GetType(); |
|
|
|
} |
|
|
|
|
|
|
|
private Control CreateVisualTreeForItem(object data) |
|
|
|
{ |
|
|
|
var visualTreeForItem = Content.Load(); |
|
|
|
visualTreeForItem.DataContext = data; |
|
|
|
return visualTreeForItem; |
|
|
|
} |
|
|
|
|
|
|
|
public Type DataType { get; set; } |
|
|
|
|
|
|
|
public TemplateContent Content { get; set; } |
|
|
|
|
|
|
|
public IControl Build(object param) |
|
|
|
{ |
|
|
|
return CreateVisualTreeForItem(param); |
|
|
|
} |
|
|
|
|
|
|
|
public bool Match(object data) |
|
|
|
private Control CreateVisualTreeForItem(object data) |
|
|
|
{ |
|
|
|
return MyMatch(data); |
|
|
|
var visualTreeForItem = Content.Load(); |
|
|
|
visualTreeForItem.DataContext = data; |
|
|
|
return visualTreeForItem; |
|
|
|
} |
|
|
|
} |
|
|
|
} |