Browse Source

Handle nulls in DataTemplate.

pull/58/head
Steven Kirk 11 years ago
parent
commit
6f940a7b15
  1. 6
      Perspex.Controls/DataTemplate.cs
  2. 6
      Perspex.Controls/Templates/DataTemplateExtensions.cs

6
Perspex.Controls/DataTemplate.cs

@ -12,7 +12,7 @@ namespace Perspex.Controls
public class DataTemplate : IDataTemplate
{
public static readonly DataTemplate Default =
new DataTemplate(typeof(object), o => new TextBlock { Text = o.ToString() });
new DataTemplate(typeof(object), o => (o != null) ? new TextBlock { Text = o.ToString() } : null);
public DataTemplate(Func<object, Control> build)
: this(o => true, build)
@ -39,7 +39,9 @@ namespace Perspex.Controls
public static bool IsInstance(object o, Type t)
{
return t.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo());
return (o != null) ?
t.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo()) :
false;
}
bool IDataTemplate.Match(object data)

6
Perspex.Controls/Templates/DataTemplateExtensions.cs

@ -20,7 +20,11 @@ namespace Perspex.Controls.Templates
if (template != null)
{
result = template.Build(data);
result.DataContext = data;
if (result != null)
{
result.DataContext = data;
}
}
else if (data is Control)
{

Loading…
Cancel
Save