0

パノラマアイテムをパノラマコントロールに動的に追加していますが、問題なく正常に追加されています

しかし、リストボックスをパノラマアイテムに追加しようとすると、エラーが発生します。例外も表示されません。アプリケーションが自動的に閉じ、その後エミュレータのホーム画面が表示されます。

以下は、パノラマアイテムとリストボックスを作成するために作成したコードです。

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);

編集:

出力ウィンドウテキスト

A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
Step into: Stepping over method without symbols 'System.Reflection.RuntimeMethodInfo.InternalInvoke'
Step into: Stepping over method without symbols 'System.Reflection.MethodBase.Invoke'
Step into: Stepping over method without symbols 'System.Delegate.DynamicInvokeOne'
Step into: Stepping over method without symbols     'System.MulticastDelegate.DynamicInvokeImpl'
Step into: Stepping over method without symbols 'System.Delegate.DynamicInvoke'
Step into: Stepping over method without symbols     'System.Windows.Threading.DispatcherOperation.Invoke'
Step into: Stepping over method without symbols 'System.Windows.Threading.Dispatcher.Dispatch'
Step into: Stepping over method without symbols 'System.Windows.Threading.Dispatcher.OnInvoke'
Step into: Stepping over method without symbols 'System.Windows.Hosting.CallbackCookie.Invoke'
Step into: Stepping over method without symbols 'System.Windows.Hosting.DelegateWrapper.InternalInvoke'
Step into: Stepping over method without symbols 'System.Windows.RuntimeHost.ManagedHost.InvokeDelegate'
A first chance exception of type 'System.Exception' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in     System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'System.Exception' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
The thread '<No Name>' (0xf640c32) has exited with code 0 (0x0).
The thread '<No Name>' (0xf450ca6) has exited with code 0 (0x0).
The thread '<No Name>' (0xf050d2e) has exited with code 0 (0x0).
The thread '<No Name>' (0xf820cda) has exited with code 0 (0x0).
The thread '<No Name>' (0xecb0e52) has exited with code 0 (0x0).
4

1 に答える 1

0

DataTemplatesコードファイルで作成する代わりにDataTemplate、ページまたはAPPのリソースセクションにコードを追加します。

コメントで@igraliが言及したように、次の方法を使用すると問題が解決します

 lstAnniversaries.ItemTemplate = this.Resources["AnniversariesTemplate"] as DataTemplate;
 lstAnniversaries.Style = this.Resources["EventsListStyle"] as Style; 
于 2012-08-21T05:08:07.887 に答える