Browse Source

Trying to define DataTemplates in XAML.

Getting a crash from OmniXAML.
pull/237/head
Steven Kirk 11 years ago
parent
commit
328f4c95d6
  1. 52
      samples/XamlTestApplication/MainViewModel.cs
  2. 22
      samples/XamlTestApplication/ViewModels/MainWindowViewModel.cs
  3. 17
      samples/XamlTestApplication/ViewModels/TestItem.cs
  4. 3
      samples/XamlTestApplication/Views/MainWindow.cs
  5. 23
      samples/XamlTestApplication/Views/MainWindow.paml
  6. 3
      samples/XamlTestApplication/XamlTestApplication.csproj
  7. 2
      src/Markup/Perspex.Markup.Xaml/Context/PerspexObjectAssembler.cs
  8. 2
      src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs
  9. 2
      src/Markup/Perspex.Markup.Xaml/OmniXAML
  10. 2
      src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj
  11. 2
      src/Markup/Perspex.Markup.Xaml/Templates/DataTemplate.cs

52
samples/XamlTestApplication/MainViewModel.cs

@ -1,52 +0,0 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
using ReactiveUI;
namespace XamlTestApplication
{
public class MainViewModel : ReactiveObject
{
private string _name;
public MainViewModel()
{
Name = "Jos\u00E9 Manuel";
People = new List<Person>
{
new Person("a little bit of Monica in my life"),
new Person("a little bit of Erica by my side"),
new Person("a little bit of Rita is all I need"),
new Person("a little bit of Tina is what I see"),
new Person("a little bit of Sandra in the sun"),
new Person("a little bit of Mary all night long"),
new Person("a little bit of Jessica here I am"),
};
}
public string Name
{
get { return _name; }
set { this.RaiseAndSetIfChanged(ref _name, value); }
}
public List<Person> People { get; set; }
}
public class Person
{
private string _name;
public Person(string name)
{
_name = name;
}
public string Name
{
get { return _name; }
set { _name = value; }
}
}
}

22
samples/XamlTestApplication/ViewModels/MainWindowViewModel.cs

@ -0,0 +1,22 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
namespace XamlTestApplication.ViewModels
{
public class MainWindowViewModel
{
public MainWindowViewModel()
{
Items = new List<TestItem>();
for (int i = 0; i < 10; ++i)
{
Items.Add(new TestItem($"Item {i}", $"Item {i} Value"));
}
}
public List<TestItem> Items { get; }
}
}

17
samples/XamlTestApplication/ViewModels/TestItem.cs

@ -0,0 +1,17 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace XamlTestApplication.ViewModels
{
public class TestItem
{
public TestItem(string header, string subheader)
{
Header = header;
SubHeader = subheader;
}
public string Header { get; }
public string SubHeader { get; }
}
}

3
samples/XamlTestApplication/Views/MainWindow.cs

@ -10,6 +10,7 @@ using OmniXaml;
using Perspex.Controls;
using Perspex.Diagnostics;
using Perspex.Markup.Xaml;
using XamlTestApplication.ViewModels;
namespace XamlTestApplication.Views
{
@ -18,7 +19,7 @@ namespace XamlTestApplication.Views
public MainWindow()
{
InitializeComponent();
DataContext = new MainWindowViewModel();
DevTools.Attach(this);
}

23
samples/XamlTestApplication/Views/MainWindow.paml

@ -1,6 +1,7 @@
<Window x:Class="XamlTestApplication.MainWindow"
xmlns="https://github.com/perspex"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:XamlTestApplication.ViewModels;assembly=XamlTestApplication"
Title="Perspex Test Application" Height="350" Width="525" SizeToContent="WidthAndHeight" >
<Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*,*">
@ -49,20 +50,14 @@
</TabItem>
<TabItem Header="Lists">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<ListBox>
<ListBoxItem>
<StackPanel>
<TextBlock Text="Item 1" FontSize="24" />
<TextBlock Text="Item 1 Value" />
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel>
<TextBlock Text="Item 2" FontSize="24" />
<TextBlock Text="Item 2 Value" />
</StackPanel>
</ListBoxItem>
</ListBox>
<ListBox Items="{Binding Items}">
<ListBox.DataTemplates>
<DataTemplate DataType="vm:TestItem">
<TextBlock Text="{Binding Header}" FontSize="24"/>
<TextBlock Text="{Binding SubHeader}"/>
</DataTemplate>
</ListBox.DataTemplates>
</ListBox>
<DropDown VerticalAlignment="Center">
<StackPanel>
<TextBlock Text="Item 1" FontSize="24" />

3
samples/XamlTestApplication/XamlTestApplication.csproj

@ -77,9 +77,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="App.cs" />
<Compile Include="MainViewModel.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\MainWindowViewModel.cs" />
<Compile Include="ViewModels\TestItem.cs" />
<Compile Include="Views\MainWindow.cs" />
</ItemGroup>
<ItemGroup>

2
src/Markup/Perspex.Markup.Xaml/Context/PerspexObjectAssembler.cs

@ -15,7 +15,7 @@ namespace Perspex.Markup.Xaml.Context
public PerspexObjectAssembler(IWiringContext wiringContext, ObjectAssemblerSettings objectAssemblerSettings = null)
{
var mapping = new DeferredLoaderMapping();
mapping.Map<XamlDataTemplate>(template => template.Content, new TemplateLoader());
mapping.Map<DataTemplate>(template => template.Content, new TemplateLoader());
var assembler = new ObjectAssembler(wiringContext, new TopDownValueContext(), objectAssemblerSettings);
_objectAssembler = new TemplateHostingObjectAssembler(assembler, mapping);

2
src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs

@ -107,7 +107,7 @@ namespace Perspex.Markup.Xaml.Context
new ContentPropertyDefinition(typeof(Style), "Setters"),
new ContentPropertyDefinition(typeof(TextBlock), "Text"),
new ContentPropertyDefinition(typeof(TextBox), "Text"),
new ContentPropertyDefinition(typeof(XamlDataTemplate), "Content"),
new ContentPropertyDefinition(typeof(DataTemplate), "Content"),
};
contentPropertyProvider.AddAll(contentProperties);

2
src/Markup/Perspex.Markup.Xaml/OmniXAML

@ -1 +1 @@
Subproject commit 1461be589a5d39d378fd177648c61a780271c742
Subproject commit 1aa1e5080b04ccf40baef4420ee29ffef9303811

2
src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj

@ -242,7 +242,7 @@
<Compile Include="Context\PerspexXamlMember.cs" />
<Compile Include="Context\PerspexXamlMemberValuePlugin.cs" />
<Compile Include="Context\PerspexXamlType.cs" />
<Compile Include="Templates\XamlDataTemplate.cs" />
<Compile Include="Templates\DataTemplate.cs" />
<Compile Include="PerspexXamlLoader.cs" />
</ItemGroup>
<ItemGroup>

2
src/Markup/Perspex.Markup.Xaml/Templates/DataTemplate.cs

@ -9,7 +9,7 @@ using Perspex.Controls.Templates;
namespace Perspex.Markup.Xaml.Templates
{
[ContentProperty("Content")]
public class XamlDataTemplate : IDataTemplate
public class DataTemplate : IDataTemplate
{
private bool MyMatch(object data)
{

Loading…
Cancel
Save