Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义列表WPF中的自定义对象_Wpf_Xaml_Custom Collection - Fatal编程技术网

自定义列表WPF中的自定义对象

自定义列表WPF中的自定义对象,wpf,xaml,custom-collection,Wpf,Xaml,Custom Collection,我有一个叫做日历的视图模型 在Calendar中,有CalendarDaySquare对象的列表。它们显示在作为uniformgrid的ItemsControl中(来自ItemsPanelTemplate) 在每个calendarDaySquares上,我想用(CalEvent对象的)事件集合填充它 公共类日历 { //这只是一个从列表继承的列表 公共日历平方列表平方{get;private set;} } 公共类日历日广场 { 公共列表事件{get;private set;} 公共observ

我有一个叫做日历的视图模型

在Calendar中,有CalendarDaySquare对象的列表。它们显示在作为uniformgrid的ItemsControl中(来自ItemsPanelTemplate)

在每个calendarDaySquares上,我想用(CalEvent对象的)事件集合填充它

公共类日历
{
//这只是一个从列表继承的列表
公共日历平方列表平方{get;private set;}
}
公共类日历日广场
{
公共列表事件{get;private set;}
公共observeCollection ObsColEvents{get;private set;}
}
都是一样的,我只是试着使用了我一直被难倒的可观察到的收集b/c

这是我的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>


我希望我已经粘贴了最新的(我已经为此工作了一整天,所以这正是我在VS中得到的..悲伤的脸)

好吧,我想我已经了解了这一点,但我希望得到任何建议

我在努力学习。我没有意识到它会自动拾取它的类型。因此,这起了作用:

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

Yep,这就是数据绑定的美妙之处,对象的类型(实际上,对象本身)被传递到模板中,因此您可以执行非常复杂的绑定技巧。
<ListBox ItemsSource="{Binding Events}">
                            <ListBox.ItemTemplate>
                                <DataTemplate >
                                    <Button HorizontalAlignment="Stretch">
                                        <TextBlock Text="{Binding Name}"/>
                                    </Button>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>