Browse Source

WIP

pull/4/head
Steven Kirk 12 years ago
parent
commit
1c2a72be11
  1. 9
      Perspex/Controls/Control.cs
  2. 43
      Perspex/Controls/HeaderedContentControl.cs
  3. 4
      Perspex/Controls/ItemsPresenter.cs
  4. 12
      Perspex/Controls/Tab.cs
  5. 27
      Perspex/Controls/TabStrip.cs
  6. 13
      Perspex/IHeadered.cs
  7. 6
      Perspex/Perspex.csproj
  8. 3
      Perspex/Themes/Default/DefaultTheme.cs
  9. 3
      Perspex/Themes/Default/ItemsControlStyle.cs
  10. 39
      Perspex/Themes/Default/TabStripStyle.cs
  11. 42
      Perspex/Themes/Default/TabStyle.cs
  12. 32
      TestApplication/Program.cs

9
Perspex/Controls/Control.cs

@ -212,8 +212,15 @@ namespace Perspex.Controls
});
}
protected DataTemplate FindDataTemplate(object content)
protected virtual DataTemplate FindDataTemplate(object content)
{
IVisual visual = content as IVisual;
if (visual != null)
{
return new DataTemplate(_ => true, x => visual);
}
ILogical node = this;
while (node != null)

43
Perspex/Controls/HeaderedContentControl.cs

@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
// <copyright file="ContentControl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
using System.Linq;
public class HeaderedContentControl : ContentControl, ILogical, IHeadered
{
public static readonly PerspexProperty<object> HeaderProperty =
PerspexProperty.Register<ContentControl, object>("Header");
public object Header
{
get { return this.GetValue(HeaderProperty); }
set { this.SetValue(HeaderProperty, value); }
}
IEnumerable<ILogical> ILogical.LogicalChildren
{
get
{
ILogical logicalContent = this.Content as ILogical;
ILogical logicalHeader = this.Header as ILogical;
if (logicalContent != null)
{
yield return logicalContent;
}
if (logicalHeader != null)
{
yield return logicalHeader;
}
}
}
}
}

4
Perspex/Controls/ItemsPresenter.cs

@ -15,10 +15,10 @@ namespace Perspex.Controls
public class ItemsPresenter : Control, IVisual
{
public static readonly PerspexProperty<IEnumerable> ItemsProperty =
PerspexProperty.Register<ItemsControl, IEnumerable>("Items");
PerspexProperty.Register<ItemsPresenter, IEnumerable>("Items");
public static readonly PerspexProperty<ItemsPanelTemplate> ItemsPanelProperty =
PerspexProperty.Register<ItemsControl, ItemsPanelTemplate>("ItemsPanel");
PerspexProperty.Register<ItemsPresenter, ItemsPanelTemplate>("ItemsPanel");
private Panel panel;

12
Perspex/Controls/Tab.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex.Controls
{
public class Tab : ContentControl
{
}
}

27
Perspex/Controls/TabStrip.cs

@ -0,0 +1,27 @@
// -----------------------------------------------------------------------
// <copyright file="TabStrip.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
using System.Linq;
public class TabStrip : ItemsControl
{
private static readonly DataTemplate TabTemplate = new DataTemplate(_ => true, CreateTab);
protected override DataTemplate FindDataTemplate(object content)
{
return TabTemplate;
}
private static IVisual CreateTab(object o)
{
return new Tab { Content = o };
}
}
}

13
Perspex/IHeadered.cs

@ -0,0 +1,13 @@
// -----------------------------------------------------------------------
// <copyright file="IHeadered.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
public interface IHeadered
{
object Header { get; set; }
}
}

6
Perspex/Perspex.csproj

@ -70,6 +70,9 @@
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="BindingExtensions.cs" />
<Compile Include="Controls\HeaderedContentControl.cs" />
<Compile Include="Controls\Tab.cs" />
<Compile Include="Controls\TabStrip.cs" />
<Compile Include="Controls\ItemsPresenter.cs" />
<Compile Include="Controls\ItemsPanelTemplate.cs" />
<Compile Include="Controls\ItemsControl.cs" />
@ -90,6 +93,7 @@
<Compile Include="Controls\LogicalChildren.cs" />
<Compile Include="Controls\Panel.cs" />
<Compile Include="Controls\StackPanel.cs" />
<Compile Include="IHeadered.cs" />
<Compile Include="Input\InputElement.cs" />
<Compile Include="Input\IFocusManager.cs" />
<Compile Include="Input\FocusManager.cs" />
@ -128,6 +132,8 @@
<Compile Include="Media\Stretch.cs" />
<Compile Include="Themes\Default\ContentControlStyle.cs" />
<Compile Include="Themes\Default\ItemsControlStyle.cs" />
<Compile Include="Themes\Default\TabStyle.cs" />
<Compile Include="Themes\Default\TabStripStyle.cs" />
<Compile Include="Vector.cs" />
<Compile Include="Rendering\RenderManager.cs" />
<Compile Include="Rendering\IRenderManager.cs" />

3
Perspex/Themes/Default/DefaultTheme.cs

@ -17,7 +17,8 @@ namespace Perspex.Themes.Default
this.Add(new ContentControlStyle());
this.Add(new ItemsControlStyle());
this.Add(new TextBoxStyle());
this.Add(new ItemsControlStyle());
this.Add(new TabStyle());
this.Add(new TabStripStyle());
}
}
}

3
Perspex/Themes/Default/ItemsControlStyle.cs

@ -6,11 +6,8 @@
namespace Perspex.Themes.Default
{
using System;
using System.Linq;
using Perspex.Controls;
using Perspex.Media;
using Perspex.Shapes;
using Perspex.Styling;
public class ItemsControlStyle : Styles

39
Perspex/Themes/Default/TabStripStyle.cs

@ -0,0 +1,39 @@
// -----------------------------------------------------------------------
// <copyright file="TabStripStyle.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Themes.Default
{
using System.Linq;
using Perspex.Controls;
using Perspex.Media;
using Perspex.Styling;
public class TabStripStyle : Styles
{
public TabStripStyle()
{
this.AddRange(new[]
{
new Style(x => x.OfType<TabStrip>())
{
Setters = new[]
{
new Setter(Button.TemplateProperty, ControlTemplate.Create<TabStrip>(this.Template)),
},
},
});
}
private Control Template(TabStrip control)
{
return new ItemsPresenter
{
ItemsPanel = new ItemsPanelTemplate(() => new StackPanel()),
[~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty],
};
}
}
}

42
Perspex/Themes/Default/TabStyle.cs

@ -0,0 +1,42 @@
// -----------------------------------------------------------------------
// <copyright file="TabStyle.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Themes.Default
{
using System.Linq;
using Perspex.Controls;
using Perspex.Media;
using Perspex.Styling;
public class TabStyle : Styles
{
public TabStyle()
{
this.AddRange(new[]
{
new Style(x => x.OfType<Tab>())
{
Setters = new[]
{
new Setter(Button.TemplateProperty, ControlTemplate.Create<Tab>(this.Template)),
},
},
});
}
private Control Template(Tab control)
{
return new Border
{
Background = Brushes.Red,
Content = new ContentPresenter
{
[~ContentPresenter.ContentProperty] = control[~Tab.ContentProperty],
}
};
}
}
}

32
TestApplication/Program.cs

@ -70,37 +70,13 @@ namespace TestApplication
Source = new Bitmap("github_icon.png"),
Width = 200,
},
new ItemsControl
new TabStrip
{
DataTemplates = new DataTemplates
{
new DataTemplate<Item>(o => new Border
{
Background = Brushes.Red,
BorderBrush = Brushes.Black,
BorderThickness = 1,
Content = new StackPanel
{
Orientation = Orientation.Vertical,
Children = new PerspexList<Control>
{
new TextBlock
{
Text = o.Name,
},
new TextBlock
{
Text = o.Value,
}
},
}
}),
},
Items = new[]
{
new Item { Name = "Foo", Value = "Bar" },
new Item { Name = "Buzz", Value = "Aldrin" },
},
"Foo",
"Bar",
}
}
}
}

Loading…
Cancel
Save