Browse Source

Merge remote-tracking branch 'origin/master' into dropdown

pull/39/head
Steven Kirk 11 years ago
parent
commit
547d58b5ce
  1. 12
      Perspex.Controls/DataTemplate.cs
  2. 8
      Perspex.Controls/DataTemplateExtensions.cs
  3. 2
      Perspex.Controls/DataTemplates.cs
  4. 2
      Perspex.Controls/Generators/TreeItemContainerGenerator.cs
  5. 15
      Perspex.Controls/IDataTemplate.cs
  6. 1
      Perspex.Controls/Perspex.Controls.csproj
  7. 2
      Perspex.Controls/Presenters/ContentPresenter.cs
  8. 80
      Perspex.SceneGraph/LogicalTree/LogicalExtensions.cs
  9. 1
      Perspex.SceneGraph/Perspex.SceneGraph.csproj

12
Perspex.Controls/DataTemplate.cs

@ -9,7 +9,7 @@ namespace Perspex.Controls
using System;
using System.Reflection;
public class DataTemplate
public class DataTemplate : IDataTemplate
{
public static readonly DataTemplate Default =
new DataTemplate(typeof(object), o => new TextBlock { Text = o.ToString() });
@ -41,6 +41,16 @@ namespace Perspex.Controls
{
return t.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo());
}
bool IDataTemplate.Match(object data)
{
return this.Match(data);
}
Control IDataTemplate.Build(object data)
{
return this.Build(data);
}
}
public class DataTemplate<T> : DataTemplate

8
Perspex.Controls/DataTemplateExtensions.cs

@ -14,7 +14,7 @@ namespace Perspex.Controls
{
public static Control ApplyDataTemplate(this Control control, object data)
{
DataTemplate result = control.FindDataTemplate(data);
IDataTemplate result = control.FindDataTemplate(data);
if (result != null)
{
@ -30,12 +30,12 @@ namespace Perspex.Controls
}
}
public static DataTemplate FindDataTemplate(this Control control, object data)
public static IDataTemplate FindDataTemplate(this Control control, object data)
{
// TODO: This needs to traverse the logical tree, not the visual.
foreach (var i in control.GetSelfAndVisualAncestors().OfType<Control>())
{
foreach (DataTemplate dt in i.DataTemplates.Reverse())
foreach (IDataTemplate dt in i.DataTemplates.Reverse())
{
if (dt.Match(data))
{
@ -48,7 +48,7 @@ namespace Perspex.Controls
if (global != null)
{
foreach (DataTemplate dt in global.DataTemplates.Reverse())
foreach (IDataTemplate dt in global.DataTemplates.Reverse())
{
if (dt.Match(data))
{

2
Perspex.Controls/DataTemplates.cs

@ -8,7 +8,7 @@ namespace Perspex.Controls
{
using Perspex.Collections;
public class DataTemplates : PerspexList<DataTemplate>
public class DataTemplates : PerspexList<IDataTemplate>
{
}
}

2
Perspex.Controls/Generators/TreeItemContainerGenerator.cs

@ -52,7 +52,7 @@ namespace Perspex.Controls.Generators
private TreeDataTemplate GetTreeDataTemplate(object item)
{
DataTemplate template = this.Owner.FindDataTemplate(item);
IDataTemplate template = this.Owner.FindDataTemplate(item);
if (template == null)
{

15
Perspex.Controls/IDataTemplate.cs

@ -0,0 +1,15 @@
// -----------------------------------------------------------------------
// <copyright file="IDataTemplate.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
public interface IDataTemplate
{
bool Match(object data);
Control Build(object data);
}
}

1
Perspex.Controls/Perspex.Controls.csproj

@ -41,6 +41,7 @@
<Compile Include="Platform\IPopupImpl.cs" />
<Compile Include="Platform\ITopLevelImpl.cs" />
<Compile Include="Popup.cs" />
<Compile Include="IDataTemplate.cs" />
<Compile Include="RadioButton.cs" />
<Compile Include="CheckBox.cs" />
<Compile Include="ColumnDefinition.cs" />

2
Perspex.Controls/Presenters/ContentPresenter.cs

@ -110,7 +110,7 @@ namespace Perspex.Controls.Presenters
}
else
{
DataTemplate dataTemplate = this.FindDataTemplate(content);
IDataTemplate dataTemplate = this.FindDataTemplate(content);
if (dataTemplate != null)
{

80
Perspex.SceneGraph/LogicalTree/LogicalExtensions.cs

@ -0,0 +1,80 @@
// -----------------------------------------------------------------------
// <copyright file="LogicalExtensions.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.LogicalTree
{
using System;
using System.Collections.Generic;
using System.Linq;
public static class LogicalExtensions
{
public static IEnumerable<ILogical> GetLogicalAncestors(this ILogical logical)
{
Contract.Requires<NullReferenceException>(logical != null);
logical = logical.LogicalParent;
while (logical != null)
{
yield return logical;
logical = logical.LogicalParent;
}
}
public static IEnumerable<ILogical> GetSelfAndLogicalAncestors(this ILogical logical)
{
yield return logical;
foreach (var ancestor in logical.GetLogicalAncestors())
{
yield return ancestor;
}
}
public static IEnumerable<ILogical> GetLogicalChildren(this ILogical logical)
{
return logical.LogicalChildren;
}
public static IEnumerable<ILogical> GetLogicalDescendents(this ILogical logical)
{
foreach (ILogical child in logical.LogicalChildren)
{
yield return child;
foreach (ILogical descendent in child.GetLogicalDescendents())
{
yield return descendent;
}
}
}
public static ILogical GetLogicalParent(this ILogical logical)
{
return logical.LogicalParent;
}
public static T GetLogicalParent<T>(this ILogical logical) where T : class
{
return logical.LogicalParent as T;
}
public static IEnumerable<ILogical> GetLogicalSiblings(this ILogical logical)
{
ILogical parent = logical.LogicalParent;
if (parent != null)
{
foreach (ILogical sibling in parent.LogicalChildren)
{
yield return sibling;
}
}
}
}
}

1
Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -92,6 +92,7 @@
<Compile Include="Thickness.cs" />
<Compile Include="Vector.cs" />
<Compile Include="Visual.cs" />
<Compile Include="LogicalTree\LogicalExtensions.cs" />
<Compile Include="VisualTree\VisualExtensions.cs" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save