Skip to content

Commit

Permalink
https://github.com/morganstanley/ComposeUI/issues/47
Browse files Browse the repository at this point in the history
added a simple reference application showing communications between different visual plugins via a shared view model.
  • Loading branch information
polyanic committed Jul 13, 2022
1 parent 55b7bcc commit 3e329c6
Show file tree
Hide file tree
Showing 18 changed files with 963 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ See the License for the specific language governing permissions and limitations
<AvaloniaResource Include="Views\AuthenticationView.axaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.13" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.13" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.13" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ See the License for the specific language governing permissions and limitations
<ItemGroup>
<None Remove=".gitignore" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.13" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.13" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\MorganStanley.ComposeUI.Playground.VisualUtils\MorganStanley.ComposeUI.Playground.VisualUtils.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(OutDir)\$(AssemblyName).dll&quot; &quot;$(SolutionDir)\bin\$(Configuration)\net6.0\Plugins\ViewPlugins\$(ProjectName)\&quot; /R /Y /I" />
<Exec Command="xcopy &quot;$(OutDir)\$(AssemblyName).pdb&quot; &quot;$(SolutionDir)\bin\$(Configuration)\net6.0\Plugins\ViewPlugins\$(ProjectName)\&quot; /R /Y /I" />
</Target>

<ItemGroup>
<ProjectReference Include="..\..\..\MorganStanley.ComposeUI.Playground.VisualUtils\MorganStanley.ComposeUI.Playground.VisualUtils.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:np="https://np.com/visuals">
<DataTemplate x:Key="StudentDetailView">
<np:AutoGrid DataContext="{Binding Path=TheSelectedItem}">
<np:AutoGrid.Styles>
<Style Selector="np|LabeledControl">
<Setter Property="ContainedControlTemplate">
<Setter.Value>
<ControlTemplate>
<TextBlock Text="{Binding}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Margin"
Value="0,0,0,10"/>
</Style>
</np:AutoGrid.Styles>
<np:LabeledControl Text="First Name:"
DataContext="{Binding Path=FirstName}"/>
<np:LabeledControl Text="Last Name:"
DataContext="{Binding Path=LastName}"
np:AutoGrid.Row="1"/>
<np:LabeledControl Text="Major:"
DataContext="{Binding Path=Major}"
np:AutoGrid.Row="2"/>
</np:AutoGrid>
</DataTemplate>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(OutDir)\$(AssemblyName).dll&quot; &quot;$(SolutionDir)\bin\$(Configuration)\net6.0\Plugins\ViewPlugins\$(ProjectName)\&quot; /R /Y /I" />
<Exec Command="xcopy &quot;$(OutDir)\$(AssemblyName).pdb&quot; &quot;$(SolutionDir)\bin\$(Configuration)\net6.0\Plugins\ViewPlugins\$(ProjectName)\&quot; /R /Y /I" />
</Target>

<ItemGroup>
<ProjectReference Include="..\..\..\MorganStanley.ComposeUI.Playground.VisualUtils\MorganStanley.ComposeUI.Playground.VisualUtils.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="StudentsDataGrid">
<DataGrid AutoGenerateColumns="False"
Items="{Binding}"
SelectedItem="{Binding TheSelectedItem, Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name"
Binding="{Binding Path=FirstName}"/>
<DataGridTextColumn Header="Last Name"
Binding="{Binding Path=LastName}"/>
<DataGridTextColumn Header="Major"
Binding="{Binding Path=Major}"/>
</DataGrid.Columns>

</DataGrid>
</DataTemplate>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NP.Concepts.Behaviors;
using System;

namespace MorganStanley.GridSelectionPrototype
{
public class Student : SelectableItem<Student>
{
public int StudentID { get; set; }

public string? FirstName { get; set; }

public string? LastName { get; set; }

public string? Major { get; set; }

public override string ToString()
{
return $"{FirstName} {LastName}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(OutDir)\$(AssemblyName).dll&quot; &quot;$(SolutionDir)\bin\$(Configuration)\net6.0\Plugins\ViewModelPlugins\$(ProjectName)\&quot; /R /Y /I" />
<Exec Command="xcopy &quot;$(OutDir)\$(AssemblyName).pdb&quot; &quot;$(SolutionDir)\bin\$(Configuration)\net6.0\Plugins\ViewModelPlugins\$(ProjectName)\&quot; /R /Y /I" />
</Target>
<ItemGroup>
<ProjectReference Include="..\..\..\MorganStanley.ComposeUI.Playground.BasicModels\MorganStanley.ComposeUI.Playground.BasicModels.csproj" />
<ProjectReference Include="..\..\..\MorganStanley.ComposeUI.Playground.Interfaces\MorganStanley.ComposeUI.Playground.Interfaces.csproj" />
<ProjectReference Include="..\..\..\MorganStanley.ComposeUI.Playground.Utilities\MorganStanley.ComposeUI.Playground.Utilities.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using NP.Concepts.Behaviors;
using NP.Utilities.Attributes;
using NP.Utilities.PluginUtils;

namespace MorganStanley.GridSelectionPrototype
{
[Implements(typeof(IPlugin), partKey:"StudentsViewModel", IsSingleton = true)]
public class TestStudents : SingleSelectionObservableCollection<Student>, IPlugin
{
private int _currentId = 0;

private void AddStudent(string firstName, string lastName, string major)
{
_currentId++;

Student student = new Student { StudentID = _currentId, FirstName = firstName, LastName = lastName, Major = major };

this.Add(student);
}

public TestStudents()
{
AddStudent("Joe", "Doe", "Math");
AddStudent("Sonny", "Corleone", "Liberal Arts");
AddStudent("Johny", "Fontane", "Singing");
}

public override string? ToString()
{
return TheSelectedItem?.ToString() ?? base.ToString();
}
}
}
Loading

0 comments on commit 3e329c6

Please sign in to comment.