Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.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
Silverlight 使用WrapPanel绑定ItemsControl?_Silverlight_Windows Phone 7 - Fatal编程技术网

Silverlight 使用WrapPanel绑定ItemsControl?

Silverlight 使用WrapPanel绑定ItemsControl?,silverlight,windows-phone-7,Silverlight,Windows Phone 7,我已使用WrapPanel将ItemsControl设置为: <ItemsControl Grid.Row="1" Height="200" Width="420" HorizontalAlignment="Center" Name="itemsMarks" VerticalAlignment="Top"> <ItemsControl.ItemsPanel> <ItemsPanelTem

我已使用WrapPanel将ItemsControl设置为:

            <ItemsControl Grid.Row="1" Height="200" Width="420" HorizontalAlignment="Center" Name="itemsMarks" VerticalAlignment="Top">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                    <Image Margin="1"  
                                VerticalAlignment="Center"
                                Source="Images/markg.png"
                                Width="70"
                                Height="70" />
                        <TextBlock TextWrapping="Wrap" Foreground="Black" Text="{Binding timestamp}" FontSize="14" HorizontalAlignment="Center" />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
         </ItemsControl>

我的数据是

    private class mark_item
    {
        public mark_item()
        {
            this.timestamp= "";
        }
        public string timestamp { get; set; }
    }

    private List<mark_item> marks;

    itemsMarks.ItemsSource = marks;
private class标记\u项
{
公共标志项目()
{
这个。timestamp=“”;
}
公共字符串时间戳{get;set;}
}
私人名单标记;
itemsMarks.ItemsSource=标记;
列表标记已正确创建,WrapPanel实际上包含列表中的项目数,但TextBlock未设置其文本属性

我错过了什么


谢谢

您需要将您的
标记项目
类别声明为
公共
,而不是
私人

Silverlight中的数据绑定只能访问
public
类和属性。通过声明类
private
,您将阻止Silverlight访问它

我接受了您的代码,看到了与您描述的相同的行为。
ItemsControl
中出现了正确数量的项,但缺少文本。在VisualStudio/Visual Web Developer Express的输出窗口中,我还看到了以下消息。(由于消息本身足够长,我省略了stacktrace):

System.Windows.Data错误:无法从“PrivateClassProblem.MainPage+标记项”(类型“PrivateClassProblem.MainPage+标记项”)获取“timestamp”值(类型“System.String”)。BindingExpression:Path='timestamp'DataItem='PrivateClassProblem.MainPage+mark_item'(HashCode=12905972);目标元素是“System.Windows.Controls.TextBlock”(名称=“”);目标属性为“Text”(类型为“System.String”)。。System.MethodAccessException:尝试通过方法“System.Windows.CLRPropertyListener.get_Value()”访问方法“PrivateClassProblem.MainPage+标记_项。get_时间戳()”失败


当我声明类
public
时,问题就消失了。

您没有在
项控件
和列表数据之间创建正确的绑定。设置
ItemsSource
属性是不够的。如果调试应用程序,您应该会在visual studio的输出窗口中看到一些绑定警告,是否可以发布其中一个?