Custom Objects in Custom List WPF

910 Views Asked by At

I have a viewmodel called Calendar.

in Calendar there is a list of CalendarDaySquare objects. They are displayed in a ItemsControl that is a uniformgrid (from the ItemsPanelTemplate).

On each of these calendarDaySquares I want to populate it with the Events Collection (of CalEvent objects)

public Class Calendar

{

// this is just a list that inherits from List<T> 
      public CalendarSquareList<CalendarDaySquare> Squares { get; private set; }

}

public class CalendarDaySquare
{

        public List<CalEvent> Events {get; private set;}

        public ObservableCollection<string> ObsColEvents{get; private set;}
}

Are the same thing, I just tried using the ObservableCollection b/c I've been stumped on this.

Here is my xaml :

<ItemsControl ItemsSource="{Binding Squares}"
                Margin="0,0,0,263">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>            
                        <UniformGrid Columns="7" Rows="5"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

                <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Control.Margin" Value="1"/>
                </Style>
                </ItemsControl.ItemContainerStyle>

                <ItemsControl.ItemTemplate>
                    <DataTemplate>


                                        <ListBox ItemsSource="{Binding}" Margin="5">
                                            <ListBox.ItemTemplate>
                                                <DataTemplate xmlns:local="clr-namespace:BudgetCalendarWPF.ViewModel;assembly=BudgetCalendarWPF" DataType="CalendarDaySquare">
                                                                <StackPanel Orientation="Horizontal">
                                                                    <TextBlock Text="{Binding}"/>
                                                                </StackPanel>
                                                </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                                <!--</Button>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>-->



                    </DataTemplate>

                </ItemsControl.ItemTemplate>
            </ItemsControl>

I hope i've pasted the latest (i've been working on this all day so this is just what i've got in VS currently .. sad face )

1

There are 1 best solutions below

1
On

Welp, I think i've got this kinda figured out but I'd love any suggestions.

I was trying to hard. I didn't realize it would automatically pick up the item as the type it was. so this worked :

<ListBox ItemsSource="{Binding Events}">
                            <ListBox.ItemTemplate>
                                <DataTemplate >
                                    <Button HorizontalAlignment="Stretch">
                                        <TextBlock Text="{Binding Name}"/>
                                    </Button>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>