Click here to Skip to main content
15,877,618 members
Home / Discussions / WPF


AnswerRe: Behavior/DP Question Pin
Richard Deeming23-Jun-20 4:44
mveRichard Deeming23-Jun-20 4:44 
GeneralRe: Behavior/DP Question Pin
Kevin Marois1-Jul-20 8:30
professionalKevin Marois1-Jul-20 8:30 
GeneralRe: Behavior/DP Question Pin
Richard Deeming1-Jul-20 23:32
mveRichard Deeming1-Jul-20 23:32 
GeneralRe: Behavior/DP Question Pin
Kevin Marois2-Jul-20 8:49
professionalKevin Marois2-Jul-20 8:49 
Question2 xaml windows question Pin
Michele Smith26-May-20 7:10
Michele Smith26-May-20 7:10 
AnswerRe: 2 xaml windows question Pin
#realJSOP26-May-20 7:43
mve#realJSOP26-May-20 7:43 
QuestionCreate DataGrid From List<T> With Properties As Columns Pin
Kevin Marois18-May-20 7:14
professionalKevin Marois18-May-20 7:14 
AnswerRe: Create DataGrid From List<T> With Properties As Columns Pin
Richard Deeming18-May-20 8:47
mveRichard Deeming18-May-20 8:47 
I suspect you're going to need a CustomTypeDescriptor for the floor view-model.
CustomTypeDescriptor Class (System.ComponentModel) | Microsoft Docs[^]

Perhaps something like this:
public class BuildingTypeViewModel
    public BuildingTypeViewModel(BuildingTypeEntity buildingType)
        Caption = buildingType.Caption;
        var floors = new List<BuildingFloorViewModel>(buildingType.NumberOfFloors);
        for (int floorNumber = 1; floorNumber <= buildingType.NumberOfFloors; floorNumber++)
            var floor = new BuildingFloorViewModel(buildingType, floorNumber);
            if (!floor.Packs.SchedulePacks.IsEmpty) floors.Add(floor);
        Floors = floors;
    public string Caption { get; }
    public IReadOnlyList<BuildingFloorViewModel> Floors { get; }

public class BuildingFloorViewModel
    public BuildingFloorViewModel(BuildingTypeEntity buildingType, int floorNumber)
        Floor = floorNumber;
        Packs = new BuildingFloorPacksViewModel(buildingType, floorNumber);
    public int Floor { get; }
    public BuildingFloorPacksViewModel Packs { get; }

public class BuildingFloorPacksViewModel : CustomTypeDescriptor, System.Collections.IEnumerable
    public BuildingFloorPacksViewModel(BuildingTypeEntity buildingType, int floorNumber)
        SchedulePacks = buildingType.SchedulePacks.Where(p => p.Floor == floorNumber).ToDictionary(p => p.Caption);
        var properties = SchedulePacks.Keys.Select(name => new SchedulePackPropertyDescriptor(name)).ToArray();
        PropertyDescriptors = new PropertyDescriptorCollection(properties);
    internal bool IsEmpty => SchedulePacks.Count == 0;
    private IReadOnlyDictionary<string, SchedulePackEntity> SchedulePacks { get; }
    private PropertyDescriptorCollection PropertyDescriptors { get; }
    public override PropertyDescriptorCollection GetProperties() => PropertyDescriptors;
    public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) => PropertyDescriptors;
    public System.Collections.IEnumerator GetEnumerator()
        // Need to implement IEnumerable to give you a single row in the grid:
        yield return this;
    private sealed class SchedulePackPropertyDescriptor : PropertyDescriptor
        public SchedulePackPropertyDescriptor(string name) : base(name, Array.Empty<Attribute>())
        public override Type ComponentType => typeof(BuildingFloorPacksViewModel);
        public override Type PropertyType => typeof(int);
        public override bool IsReadOnly => false;
        public override bool CanResetValue (object component) => false;
        public override void ResetValue (object component) => throw new NotSupportedException();
        public override bool ShouldSerializeValue (object component) => true;
        public override object GetValue (object component)
            var parent = (BuildingFloorPacksViewModel)component;
            return parent.SchedulePacks[Name].Days;
        public override void SetValue (object component, object value)
            var parent = (BuildingFloorPacksViewModel)component;
            parent.SchedulePacks[Name].Days = (int)value;
Bind your right-hand view to a list of BuildingTypeViewModel objects. Within each expander, bind an ItemsControl to the Floors property. Within the data template for the ItemsControl, display the Floor, and bind the grid to the Packs property. Let WPF auto-generate the columns for the grid, and it should work.

"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Create DataGrid From List<T> With Properties As Columns Pin
Kevin Marois18-May-20 8:52
professionalKevin Marois18-May-20 8:52 
QuestionWPF ListBox Pin
michaelbarb7-May-20 10:03
michaelbarb7-May-20 10:03 
AnswerRe: WPF ListBox Pin
Richard Deeming10-May-20 21:52
mveRichard Deeming10-May-20 21:52 
GeneralRe: WPF ListBox Pin
michaelbarb11-May-20 19:11
michaelbarb11-May-20 19:11 
GeneralRe: WPF ListBox Pin
Mycroft Holmes11-May-20 21:33
professionalMycroft Holmes11-May-20 21:33 
AnswerRe: WPF ListBox Pin
Gerry Schmitz11-May-20 12:42
mveGerry Schmitz11-May-20 12:42 
QuestionDesign Question Pin
Kevin Marois18-Apr-20 15:26
professionalKevin Marois18-Apr-20 15:26 
AnswerRe: Design Question Pin
Mycroft Holmes19-Apr-20 12:20
professionalMycroft Holmes19-Apr-20 12:20 
GeneralRe: Design Question Pin
Kevin Marois19-Apr-20 14:09
professionalKevin Marois19-Apr-20 14:09 
GeneralRe: Design Question Pin
Mycroft Holmes20-Apr-20 12:20
professionalMycroft Holmes20-Apr-20 12:20 
QuestionMVVM: DataGrid Cell BeginEdit Pin
Kevin Marois13-Apr-20 9:10
professionalKevin Marois13-Apr-20 9:10 
AnswerRe: MVVM: DataGrid Cell BeginEdit Pin
Richard Deeming14-Apr-20 0:36
mveRichard Deeming14-Apr-20 0:36 
GeneralRe: MVVM: DataGrid Cell BeginEdit Pin
Kevin Marois14-Apr-20 6:15
professionalKevin Marois14-Apr-20 6:15 
GeneralRe: MVVM: DataGrid Cell BeginEdit Pin
Richard Deeming14-Apr-20 6:28
mveRichard Deeming14-Apr-20 6:28 
GeneralRe: MVVM: DataGrid Cell BeginEdit Pin
Kevin Marois14-Apr-20 6:39
professionalKevin Marois14-Apr-20 6:39 
QuestionProblem in designer while creating a new window in a WPF project in Visual Studio 2010. Pin
priyamtheone13-Apr-20 3:38
priyamtheone13-Apr-20 3:38 
AnswerRe: Problem in designer while creating a new window in a WPF project in Visual Studio 2010. Pin
Gerry Schmitz13-Apr-20 6:59
mveGerry Schmitz13-Apr-20 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.