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 在WindowsPhone7中将datatemplate添加到列表框和全景项目表单程序_Silverlight_Windows Phone 7_Listbox_Windows Phone 7.1_Panorama Control - Fatal编程技术网

Silverlight 在WindowsPhone7中将datatemplate添加到列表框和全景项目表单程序

Silverlight 在WindowsPhone7中将datatemplate添加到列表框和全景项目表单程序,silverlight,windows-phone-7,listbox,windows-phone-7.1,panorama-control,Silverlight,Windows Phone 7,Listbox,Windows Phone 7.1,Panorama Control,我正在将全景项目动态添加到全景控件,它们正在成功添加,没有任何问题 但是,当我尝试将列表框添加到全景项目时,它的给出错误。我也看不到异常,应用程序自动关闭,然后我看到emulator主屏幕 下面是我编写的创建全景项目和列表框的代码 lstAnniversaries = new ListBox() lstAnniversaries.Width = 420; lstAnniversaries.HorizontalAlignment = System.W

我正在将全景项目动态添加到全景控件,它们正在成功添加,没有任何问题

但是,当我尝试将列表框添加到全景项目时,它的给出错误。我也看不到异常,应用程序自动关闭,然后我看到emulator主屏幕

下面是我编写的创建全景项目和列表框的代码

lstAnniversaries = new ListBox()
lstAnniversaries.Width = 420;
                        lstAnniversaries.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                        lstAnniversaries.Foreground = new SolidColorBrush(FacebookQueries.GetColorFromHexString("#000000"));
                        lstAnniversaries.Background = new SolidColorBrush(FacebookQueries.GetColorFromHexString("#ffffff"));
                        lstAnniversaries.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(lstUpcoming_Tap);
                        lstAnniversaries.ItemTemplate = (DataTemplate)XamlReader.Load(@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Grid  Height=""100"" Margin=""0,0,0,0"">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width=""90"" />
                <ColumnDefinition Width=""210"" />
                <ColumnDefinition Width=""*"" />
            </Grid.ColumnDefinitions>
            <Image Source=""{Binding ImageSource}"" Height=""90"" Width=""90"" Margin=""0,0,11,0"" />
            <StackPanel Grid.Column=""1"" Margin=""0,10,0,0"">
                <TextBlock Text=""{Binding NameSource}"" Style=""{StaticResource ProfileNameStyleForTextBlock}""  />
                <StackPanel Orientation=""Horizontal"" Margin=""0,-2,0,0"">
                    <TextBlock Text=""{Binding EventName}"" Foreground=""#000000"" Style=""{StaticResource EventNameStyleForTextBlock}""   />
                    <TextBlock Text=""{Binding EventDate}"" Foreground=""{Binding EventColor}"" Style=""{StaticResource EventDateStyleForTextBlock}""  />
                </StackPanel>
            </StackPanel>
            <Button VerticalAlignment=""Center"" Height=""Auto""     Name=""btnAnniversary"" Width=""75"" Margin=""5,0,0,0"" HorizontalAlignment=""Left""     Visibility=""{Binding EllipseStatus}"" Tag=""{Binding BindsDirectlyToSource=True}""     Click=""btnAnniversary_Click"" Canvas.ZIndex=""1"" Grid.Column=""2"">
                <Image  Source=""/GiftGiv;component/Assets/bubble.png"" />
            </Button>
        </Grid>
    </DataTemplate>");
                        pan_anniversaries = new PanoramaItem();
                        pan_anniversaries.HeaderTemplate =     (DataTemplate)XamlReader.Load(@"<DataTemplate     xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""     xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""><TextBlock Text=""anniversaries""    FontSize=""54"" Foreground=""Black"" Margin=""-10,0,0,0""></TextBlock></DataTemplate>");

                        Grid grd = new Grid();
                        grd.Children.Add(lstAnniversaries);

                        pan_anniversaries.Content = grd;

                        PanoramaControl.Items.Add(pan_anniversaries);
编辑: 输出windows文本

在页面或应用程序的参考资料部分添加DataTemplate代码,而不是在代码文件中创建DataTemplates

使用以下方法将解决注释中提到的@igrali问题

 lstAnniversaries.ItemTemplate = this.Resources["AnniversariesTemplate"] as DataTemplate;
 lstAnniversaries.Style = this.Resources["EventsListStyle"] as Style; 

为什么在代码中这样做?为什么不将该数据模板添加到某个键下的页面或应用程序资源中,然后通过该键检索它?您是否可以看到引发了什么异常以及何时在何处检查输出窗口debugging@igrali为什么不将该数据模板添加到某个键下的页面或应用程序资源中,然后通过该键检索它?你知道怎么做吗?我用输出窗口文本更新了我的问题,请再次检查是的,只需像在这篇博文的图片上显示的那样添加它:那么你的页面将拥有该资源。在此之后,只需执行以下操作:lstAnniversaries.DataTemplate=this.Resources[MyResourceKey]作为DataTemplate;其中MyResourceKey是您在datatemplate上设置的密钥。这将简化您的代码@伊格利哦,谢谢我会试试的,让你知道。。。
 lstAnniversaries.ItemTemplate = this.Resources["AnniversariesTemplate"] as DataTemplate;
 lstAnniversaries.Style = this.Resources["EventsListStyle"] as Style;