Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would create another model part, which represents the dual grouping that you need to have happen:</p> <p>Model Classes:</p> <pre><code>public class EmployeeModel { private readonly Employee _Employee; public DepartmentManager ManagementInfo { get; private set; } public string Name { get { return _Employee.Name; } } public string Address { get { return _Employee.Address; } } public EmployeeModel(Employee employee) { this._Employee = employee; this.ManagementInfo = new DepartmentManager(employee.Department, employee.Manager); } } public class DepartmentManager { public string Department { get; private set; } public string Manager { get; private set; } public DepartmentManager(string dept, string manager) { this.Department = dept; this.Manager= manager; } public override bool Equals(object obj) { var model = obj as DepartmentManager; if(null == model) return false; return Department.Equals(model.Department, StringComparison.InvariantCultureIgnoreCase) &amp;&amp; Manager.Equals(model.Manager, StringComparison.InvariantCultureIgnoreCase); } } </code></pre> <p>XAML:</p> <pre><code> &lt;CollectionViewSource x:Key="cvsEmpsModel" Source="{Binding EmployeesModel}"&gt; &lt;CollectionViewSource.GroupDescriptions&gt; &lt;PropertyGroupDescription PropertyName="ManagementInfo" /&gt; &lt;/CollectionViewSource.GroupDescriptions&gt; &lt;/CollectionViewSource&gt; &lt;DataTemplate DataType="{x:Type models:EmployeeModel}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="{Binding Name}" /&gt; &lt;TextBlock Text="{Binding Address}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; ... &lt;ListView ItemsSource="{Binding Source={StaticResource cvsEmpsModel}}"&gt; &lt;ListView.GroupStyle&gt; &lt;GroupStyle&gt; &lt;GroupStyle.HeaderTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal" Margin="0,10,0,3" DataContext="{Binding Items}"&gt; &lt;TextBlock Text="{Binding Path=ManagementInfo.Manager}" FontWeight="Bold" Margin="3" /&gt; &lt;TextBlock Text="{Binding Path=ManagementInfo.Department, StringFormat='({0})'}" Margin="3" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/GroupStyle.HeaderTemplate&gt; &lt;/GroupStyle&gt; &lt;/ListView.GroupStyle&gt; &lt;/ListView&gt; </code></pre> <p>Then in your Window/ViewModel:</p> <pre><code>this.EmployeesModel = new ObservableCollection&lt;EmployeeModel&gt;(MyListOfEmployersFromDB.Select(e =&gt; new EmployeeModel(e))); </code></pre> <p>Note, I've overriden <code>Equals</code> in the <code>DepartmentManager</code> class, but not <code>GetHashCode</code>, ideally you should do a custom implementation of that. I had to override equals so the grouping view source would correctly group the same entries. You could get rid of this need, buy constructing the <code>DepartmentManager</code> for the same Employees outside of the collection, and pass them into the <code>EmployeeModel</code> ctr.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload