Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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
Windows phone 7 Longlistselector Wp7在对象列表中绑定列表_Windows Phone 7_Silverlight Toolkit - Fatal编程技术网

Windows phone 7 Longlistselector Wp7在对象列表中绑定列表

Windows phone 7 Longlistselector Wp7在对象列表中绑定列表,windows-phone-7,silverlight-toolkit,Windows Phone 7,Silverlight Toolkit,您好,我在silverlight for wp7的数据绑定方面遇到一些问题。基本上,我很难绑定另一个对象列表中的列表。以下是我的课程示例 public class Movie { public Movie() { _Venues = new ObservableCollection<Venue>(); } private String _Title; public S

您好,我在silverlight for wp7的数据绑定方面遇到一些问题。基本上,我很难绑定另一个对象列表中的列表。以下是我的课程示例

public class Movie
    {

        public Movie()
        {
            _Venues = new ObservableCollection<Venue>();
        }

        private String _Title;

        public String Title
        {
            get { return _Title; }
            set { _Title = value; }
        }
        private String _Director;

        public String Director
        {
            get { return _Director; }
            set { _Director = value; }
        }
        private String _Runtime;

        public String Runtime
        {
            get { return _Runtime; }
            set { _Runtime = value; }
        }

        private ObservableCollection<Venue> _Venues;

        public ObservableCollection<Venue> Venues
        {
            get { return _Venues; }
            set { _Venues = value; }
        }

public class Venue
    {
        private String _Date;

        public String Date
        {
            get { return _Date; }
            set { _Date = value; }
        }
        private String _Time;

        public String Time
        {
            get { return _Time; }
            set { _Time = value; }
        }
    }
}
公共类电影
{
公共电影()
{
_场馆=新的可观测集合();
}
私有字符串\u标题;
公共字符串标题
{
获取{return\u Title;}
设置{u Title=value;}
}
私人字符串(u)控制器,;
公共字符串控制器
{
获取{return\u Director;}
设置{u Director=value;}
}
私有字符串\u运行时;
公共字符串运行时
{
获取{return\u Runtime;}
设置{u Runtime=value;}
}
私人可观测收集场地;
公众可观察的集合场地
{
获取{return}
设置{u=value;}
}
公共课堂场地
{
私有字符串\u日期;
公共字符串日期
{
获取{return\u Date;}
设置{u Date=value;}
}
私有字符串时间;
公共字符串时间
{
获取{return\u Time;}
设置{u Time=value;}
}
}
}
我的目的是从xaml中的场馆设置一个值:

 <!-- The template for movie items -->
        <DataTemplate x:Key="moviesItemTemplate">
            <StackPanel Grid.Column="1"  VerticalAlignment="Top">
                <StackPanel Grid.Column="1"  VerticalAlignment="Top" Orientation="Horizontal">
                    <Image delay:LowProfileImageLoader.UriSource="{Binding ImageThumb}"/>
                    <TextBlock Text="{Binding Title}" FontSize="26"  Margin="12,-12,12,6" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </StackPanel>
                <ListBox ItemsSource="{Binding Venues}">
                    <TextBlock Text="{Binding Date}" Foreground="Orange"  />
                </ListBox>
            </StackPanel>
        </DataTemplate>

 <!--ContentPanel contains details text. Place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <toolkit:LongListSelector x:Name="moviesListGropus" Background="Transparent" 
                 ItemTemplate="{StaticResource moviesItemTemplate}"
                 GroupHeaderTemplate="{StaticResource groupHeaderTemplate}"
                 GroupItemTemplate="{StaticResource groupItemTemplate}" >   
                <toolkit:LongListSelector.GroupItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel/>
                    </ItemsPanelTemplate>
                </toolkit:LongListSelector.GroupItemsPanel>
            </toolkit:LongListSelector>
        </Grid>
    </Grid>

在cs代码中,我使用手动循环来获取电影组,而不是Linq表达式,但我认为这不应该是这里的问题:

ObservableCollection<Group<Movie>> movieGroups = new ObservableCollection<Group<Movie>>();
this.moviesListGropus.ItemsSource = movieGroups;

public class Group<T> : IEnumerable<T>
        {
            public Group(string name, IEnumerable<T> items)
            {
                this.Title = name;
                this.Items = new List<T>(items);
            }

            public override bool Equals(object obj)
            {
                Group<T> that = obj as Group<T>;

                return (that != null) && (this.Title.Equals(that.Title));
            }

            public string Title
            {
                get;
                set;
            }

            public IList<T> Items
            {
                get;
                set;
            }

            #region IEnumerable<T> Members

            public IEnumerator<T> GetEnumerator()
            {
                return this.Items.GetEnumerator();
            }

            #endregion

            #region IEnumerable Members

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return this.Items.GetEnumerator();
            }

            #endregion
        }
observeCollection movieGroups=新的observeCollection();
this.moviesListGropus.ItemsSource=movieGroups;
公共类组:IEnumerable
{
公共组(字符串名称,IEnumerable项)
{
this.Title=名称;
此项=新列表(项);
}
公共覆盖布尔等于(对象对象对象)
{
组=obj作为组;
返回(that!=null)&&(this.Title.Equals(that.Title));
}
公共字符串标题
{
得到;
设置
}
公共物品
{
得到;
设置
}
#区域可数成员
公共IEnumerator GetEnumerator()
{
返回此.Items.GetEnumerator();
}
#端区
#区域可数成员
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
返回此.Items.GetEnumerator();
}
#端区
}
遗憾的是,由于stackoverflows限制,我无法提供图像,但结果可以在屏幕上看到

编辑第二部分:想法是在模板内放置另一个文本块,用于显示场馆列表中所需的时间。为此,我需要更深一层,因为场馆是一个列表,我希望从该列表中找到一个特定的对象。有什么建议吗

 <DataTemplate x:Key="moviesItemTemplate">
            <StackPanel Grid.Column="1"  VerticalAlignment="Top">
                <StackPanel Grid.Column="1"  VerticalAlignment="Top" Orientation="Horizontal">
                    <Image delay:LowProfileImageLoader.UriSource="{Binding ImageThumb}"/>
                    <TextBlock Text="{Binding Title}" FontSize="26"  Margin="12,-12,12,6" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </StackPanel>
                <ItemsControl x:Name="venueTime" ItemsSource="{Binding Path= Venue}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Time}" Foreground="Orange" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </StackPanel>
        </DataTemplate>

问题在于:

<ListBox ItemsSource="{Binding Venues}">
    <TextBlock Text="{Binding Date}" Foreground="Orange"  />
</ListBox>

我想你可能想要的是:

<ListBox ItemsSource="{Binding Venues}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Date}" Foreground="Orange" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

TextBlock
您在
ListBox
中经常使用的
TextBlock被忽略,因为它当时无效。
如果不希望使用默认行为,则需要指定如何对列表框中的项进行模板化。默认行为只是带有datacontext文本的TextBlock。因为您传递了一个对象(不是文本),所以框架正在对其调用
ToString()
,默认情况下,这将返回对象的类型,这就是您看到的对象类型。

问题在于:

<ListBox ItemsSource="{Binding Venues}">
    <TextBlock Text="{Binding Date}" Foreground="Orange"  />
</ListBox>

我想你可能想要的是:

<ListBox ItemsSource="{Binding Venues}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Date}" Foreground="Orange" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

TextBlock
您在
ListBox
中经常使用的
TextBlock被忽略,因为它当时无效。

如果不希望使用默认行为,则需要指定如何对列表框中的项进行模板化。默认行为只是带有datacontext文本的TextBlock。因为您传递了一个对象(不是文本),所以框架正在对其调用
ToString()
,默认情况下,这将返回对象的类型,这就是您看到的类型。

非常感谢您的回答。事实上,我的尝试是在预览日期写下具体地点的时间,所以如果你能给我一些建议,我想让你看看问题的编辑部分,在Items控件中显示VenueTimes。请你详细说明一下,好吗?我对Silverlight很陌生,到目前为止,它没有发挥应有的作用。我更改了再次使用我的新代码进行编辑。属性名称为
场馆
,末尾有一个S,而不是您使用的单数。如果检查“调试输出”窗口,您将看到一条关于绑定错误的错误消息,该错误的名称无效。如果你的图像也没有显示,那可能是因为你绑定到了viewmodel对象上不存在的属性(
ImageThumb
)。是的,很抱歉,图像没有问题,只是不想用代码压倒人们我得到了它的属性。关于场地,我添加了s,现在它向我展示了一切