Browse Source

More work on XAML control theme.

pull/297/head
Steven Kirk 11 years ago
parent
commit
71cd3d965b
  1. 8
      samples/XamlTestApplicationPcl/ContentControl.paml
  2. 10
      samples/XamlTestApplicationPcl/ItemsControl.paml
  3. 18
      samples/XamlTestApplicationPcl/ListBox.paml
  4. 22
      samples/XamlTestApplicationPcl/ListBoxItem.paml
  5. 19
      samples/XamlTestApplicationPcl/TreeView.paml
  6. 74
      samples/XamlTestApplicationPcl/TreeViewItem.paml
  7. 5
      samples/XamlTestApplicationPcl/XamlTestApp.paml
  8. 15
      samples/XamlTestApplicationPcl/XamlTestApplicationPcl.csproj
  9. 2
      src/Perspex.Controls/GridLength.cs
  10. 2
      src/Perspex.Controls/ItemsControl.cs
  11. 2
      src/Perspex.Themes.Default/ItemsControlStyle.cs
  12. 16
      tests/Perspex.Controls.UnitTests/GridLengthTests.cs
  13. 2
      tests/Perspex.Controls.UnitTests/ItemsControlTests.cs
  14. 2
      tests/Perspex.Controls.UnitTests/ListBoxTests.cs
  15. 2
      tests/Perspex.Controls.UnitTests/ListBoxTests_Single.cs
  16. 2
      tests/Perspex.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs
  17. 4
      tests/Perspex.Controls.UnitTests/TreeViewTests.cs

8
samples/XamlTestApplicationPcl/ContentControl.paml

@ -1,8 +1,12 @@
<Style xmlns="https://github.com/perspex" Selector="ContentControl">
<Setter Property="Template">
<ControlTemplate>
<Border Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}"/>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter Name="PART_ContentPresenter"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}"/>
</Border>
</ControlTemplate>
</Setter>

10
samples/XamlTestApplicationPcl/ItemsControl.paml

@ -0,0 +1,10 @@
<Style xmlns="https://github.com/perspex" Selector="ItemsControl">
<Setter Property="Template">
<ControlTemplate>
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
MemberSelector="{TemplateBinding MemberSelector}"/>
</ControlTemplate>
</Setter>
</Style>

18
samples/XamlTestApplicationPcl/ListBox.paml

@ -0,0 +1,18 @@
<Style xmlns="https://github.com/perspex" Selector="ListBox">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<ControlTemplate>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer>
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
MemberSelector="{TemplateBinding MemberSelector}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter>
</Style>

22
samples/XamlTestApplicationPcl/ListBoxItem.paml

@ -0,0 +1,22 @@
<Styles xmlns="https://github.com/perspex">
<Style Selector="ListBoxItem">
<Setter Property="Template">
<ControlTemplate>
<Border Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter Name="PART_ContentPresenter"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}"/>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="ListBoxItem:selected /template/ Border#border">
<Setter Property="Background" Value="#fff0f0f0"/>
</Style>
<Style Selector="ListBoxItem:selected:focus /template/ Border#border">
<Setter Property="Background" Value="#ffd0d0d0"/>
</Style>
</Styles>

19
samples/XamlTestApplicationPcl/TreeView.paml

@ -0,0 +1,19 @@
<Style xmlns="https://github.com/perspex" Selector="TreeView">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<ControlTemplate>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="4">
<ScrollViewer CanScrollHorizontally="True">
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
MemberSelector="{TemplateBinding MemberSelector}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter>
</Style>

74
samples/XamlTestApplicationPcl/TreeViewItem.paml

@ -0,0 +1,74 @@
<Styles xmlns="https://github.com/perspex">
<Style Selector="TreeViewItem">
<Setter Property="Template">
<ControlTemplate>
<StackPanel>
<Grid ColumnDefinitions="16, Auto">
<ToggleButton Name="expander"
Focusable="False"
IsChecked="{TemplateBinding Path=IsExpanded, Mode=TwoWay}"/>
<Border Name="header"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.Column="1">
<ContentPresenter Name="PART_ContentPresenter"
Content="{TemplateBinding Header}"
Margin="{TemplateBinding Padding}"/>
</Border>
<!--<Rectangle Name="focus"
IsVisible="{TemplateBinding IsFocused}"
Stroke="Black"
StrokeThickness="1"
StrokeDashArray="1,2"
Grid.Column="1"/>-->
</Grid>
<ItemsPresenter Name="PART_ItemsPresenter"
IsVisible="{TemplateBinding IsExpanded}"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
Margin="24,0,0,0"
MemberSelector="{TemplateBinding MemberSelector}"/>
</StackPanel>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="TreeViewItem /template/ ToggleButton#expander">
<Setter Property="Template">
<ControlTemplate>
<Border Width="14"
Height="12"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Path Fill="Black"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 2 L 4 6 L 0 10 Z"/>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="TreeViewItem /template/ Border#header">
<Setter Property="Padding" Value="2"/>
</Style>
<Style Selector="TreeViewItem:selected /template/ Border#header">
<Setter Property="Background" Value="#fff0f0f0"/>
</Style>
<Style Selector="TreeViewItem:selected:focus /template/ Border#header">
<Setter Property="Background" Value="#ffd0d0d0"/>
</Style>
<Style Selector="TreeViewItem /template/ ToggleButton#expander:checked">
<Setter Property="RenderTransform">
<RotateTransform Angle="45"/>
</Setter>
</Style>
<Style Selector="TreeViewItem:empty /template/ ToggleButton#expander">
<Setter Property="IsVisible" Value="False"/>
</Style>
</Styles>

5
samples/XamlTestApplicationPcl/XamlTestApp.paml

@ -5,6 +5,9 @@
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.Button.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.Carousel.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.CheckBox.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.ItemsControl.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.ListBox.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.ListBoxItem.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.RadioButton.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.ScrollBar.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.ScrollViewer.paml"/>
@ -13,6 +16,8 @@
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.TabStrip.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.TextBox.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.ToggleButton.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.TreeView.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.TreeViewItem.paml"/>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.Window.paml"/>
</Application.Styles>
</Application>

15
samples/XamlTestApplicationPcl/XamlTestApplicationPcl.csproj

@ -151,6 +151,21 @@
<EmbeddedResource Include="RadioButton.paml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="ItemsControl.paml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="ListBox.paml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="ListBoxItem.paml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="TreeView.paml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="TreeViewItem.paml">
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="packages.config" />
<EmbeddedResource Include="Button.paml">
<SubType>Designer</SubType>

2
src/Perspex.Controls/GridLength.cs

@ -210,7 +210,7 @@ namespace Perspex.Controls
/// <returns>The <see cref="GridLength"/>.</returns>
public static IEnumerable<GridLength> ParseLengths(string s, CultureInfo culture)
{
return s.Split(new[] { ',', ' ' }).Select(x => Parse(x, culture));
return s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Parse(x, culture));
}
}
}

2
src/Perspex.Controls/ItemsControl.cs

@ -149,7 +149,7 @@ namespace Perspex.Controls
/// <inheritdoc/>
protected override void OnTemplateApplied()
{
Presenter = this.FindTemplateChild<IItemsPresenter>("itemsPresenter");
Presenter = this.FindTemplateChild<IItemsPresenter>("PART_ItemsPresenter");
}
/// <summary>

2
src/Perspex.Themes.Default/ItemsControlStyle.cs

@ -41,7 +41,7 @@ namespace Perspex.Themes.Default
{
return new ItemsPresenter
{
Name = "itemsPresenter",
Name = "PART_ItemsPresenter",
MemberSelector = control.MemberSelector,
[~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty],
[~ItemsPresenter.ItemsPanelProperty] = control[~ItemsControl.ItemsPanelProperty],

16
tests/Perspex.Controls.UnitTests/GridLengthTests.cs

@ -87,5 +87,21 @@ namespace Perspex.Controls.UnitTests
},
result);
}
[Fact]
public void ParseLengths_Accepts_Comma_Separators_With_Spaces()
{
var result = GridLength.ParseLengths("*, Auto, 2* ,4", CultureInfo.InvariantCulture).ToList();
Assert.Equal(
new[]
{
new GridLength(1, GridUnitType.Star),
GridLength.Auto,
new GridLength(2, GridUnitType.Star),
new GridLength(4, GridUnitType.Pixel),
},
result);
}
}
}

2
tests/Perspex.Controls.UnitTests/ItemsControlTests.cs

@ -361,7 +361,7 @@ namespace Perspex.Controls.UnitTests
Background = new Media.SolidColorBrush(0xffffffff),
Child = new ItemsPresenter
{
Name = "itemsPresenter",
Name = "PART_ItemsPresenter",
MemberSelector = parent.MemberSelector,
[~ItemsPresenter.ItemsProperty] = parent[~ItemsControl.ItemsProperty],
}

2
tests/Perspex.Controls.UnitTests/ListBoxTests.cs

@ -97,7 +97,7 @@ namespace Perspex.Controls.UnitTests
Template = new FuncControlTemplate(CreateScrollViewerTemplate),
Content = new ItemsPresenter
{
Name = "itemsPresenter",
Name = "PART_ItemsPresenter",
[~ItemsPresenter.ItemsProperty] = parent.GetObservable(ItemsControl.ItemsProperty),
}
};

2
tests/Perspex.Controls.UnitTests/ListBoxTests_Single.cs

@ -205,7 +205,7 @@ namespace Perspex.Controls.UnitTests
Template = new FuncControlTemplate(CreateScrollViewerTemplate),
Content = new ItemsPresenter
{
Name = "itemsPresenter",
Name = "PART_ItemsPresenter",
[~ItemsPresenter.ItemsProperty] = parent.GetObservable(ItemsControl.ItemsProperty),
}
};

2
tests/Perspex.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs

@ -434,7 +434,7 @@ namespace Perspex.Controls.UnitTests.Primitives
return new FuncControlTemplate<SelectingItemsControl>(control =>
new ItemsPresenter
{
Name = "itemsPresenter",
Name = "PART_ItemsPresenter",
[~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty],
[~ItemsPresenter.ItemsPanelProperty] = control[~ItemsControl.ItemsPanelProperty],
});

4
tests/Perspex.Controls.UnitTests/TreeViewTests.cs

@ -215,7 +215,7 @@ namespace Perspex.Controls.UnitTests
{
return new FuncControlTemplate<TreeView>(parent => new ItemsPresenter
{
Name = "itemsPresenter",
Name = "PART_ItemsPresenter",
[~ItemsPresenter.ItemsProperty] = parent[~ItemsControl.ItemsProperty],
});
}
@ -224,7 +224,7 @@ namespace Perspex.Controls.UnitTests
{
return new FuncControlTemplate<TreeViewItem>(parent => new ItemsPresenter
{
Name = "itemsPresenter",
Name = "PART_ItemsPresenter",
[~ItemsPresenter.ItemsProperty] = parent[~ItemsControl.ItemsProperty],
});
}

Loading…
Cancel
Save