2009-08-05 8 views
0

J'ai ce Page.xamlPage XAML flip torsion

<UserControl x:Class="SLBookDemoApp.Page" 
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:SLMitsuControls;assembly=SLMitsuControls" 
    Width="800" Height="600" Loaded="UserControl_Loaded"> 
    <Grid> 
     <local:UCBook x:Name="book" Margin="50" /> 
    </Grid> 
</UserControl> 

Et le correspondant Page.xaml.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using SLMitsuControls; 

namespace SLBookDemoApp 
{ 
    public partial class Page : UserControl, IDataProvider 
    { 
     public Page() 
     { 
      InitializeComponent(); 
     } 

     private List<Grid> pages; 

     private void UserControl_Loaded(object sender, RoutedEventArgs e) 
     { 
      /* 
      pages = new List<Button> 
      { 
       new Button { Content = "Page 0"}, 
       new Button { Content = "Page 1", Background = new SolidColorBrush(Colors.Green) }, 
       new Button { Content = "Page 2", Background = new SolidColorBrush(Colors.Yellow) }, 
       new Button { Content = "Page 3", Background = new SolidColorBrush(Colors.Brown) }, 
       new Button { Content = "Page 4", Background = new SolidColorBrush(Colors.Magenta) }, 
       new Button { Content = "Page 5", Background = new SolidColorBrush(Colors.Red) } 
      }; 
      */ 

      System.Windows.Application.LoadComponent(this, new System.Uri("/SLBookDemoApp;PagTeste2.xaml", System.UriKind.Relative)); 
      Grid LayoutRoot = ((Grid)(FindName("LayoutRoot"))); 
      //TextBlock testTextBlock = ((TextBlock)(FindName("testTextBlock"))); 

      pages = new List<Grid> 
      { 
      }; 

      pages.Add(LayoutRoot); 
      /* 
      int i = 0; 
      foreach (var b in pages) 
      { 
       if (i % 2 == 0) 
        b.Click += Button_Click; 
       else 
        b.Click += Button_Click_1; 
       i++; 
      } 
      */ 

      book.SetData(this); 
     } 

     #region IDataProvider Members 

     public object GetItem(int index) 
     { 
      return pages[index]; 
     } 

     public int GetCount() 
     { 
      return pages.Count; 
     } 

     #endregion 

     private void Button_Click(object sender, RoutedEventArgs e) 
     { 
      book.AnimateToNextPage(500); 
     } 

     private void Button_Click_1(object sender, RoutedEventArgs e) 
     { 
      book.AnimateToPreviousPage(500); 
     } 
    } 
} 

Et le XAML je wnat à inclure est ce PagTeste2 .xaml

<Grid 
     xmlns="http://schemas.microsoft.com/client/2007" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     x:Class="SLBookDemoApp.PagTeste2" 
     x:Name="LayoutRoot"> 
     <Rectangle Width="192" Height="80" Fill="#FF8F0A0A" Stroke="#FF000000" Canvas.Left="224" Canvas.Top="104"/> 

</Grid> 

Avec le correspondant PagTeste2.xaml.cs

using System; 
using System.IO; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
//using System.Windows.Navigation; 
using SLMitsuControls; 

namespace SLBookDemoApp 
{ 
    public partial class PagTeste2 
    { 
     public PagTeste2() 
     { 
      this.InitializeComponent(); 

      // Insert code required on object creation below this point. 
     } 
    } 
} 

Je reçois une erreur sur cette ligne

System.Windows.Application.LoadComponent(this, new System.Uri("/SLBookDemoApp;PagTeste2.xaml", System.UriKind.Relative)); 

Quelqu'un sait pourquoi?

Répondre

0

Utilisez ce lieu:

this.Content = new PagTeste2(); 

Il vous suffit de faire toute sorte de chargement de montage si vous chargez un contenu à partir d'un assemblage différent et même alors, vous ne l'utiliser pour définir le contenu. Si vous demandez en fait comment charger dynamiquement un assemblage, MS have an example of how.

0

Vous pouvez essayer /SLBookDemoApp;component/PageTeste2.xaml.

+0

J'ai déjà essayé, et cela n'a pas fonctionné. Comment puis-je mettre cela au travail? – Bonfocchi

0

Si PagTeste2.xaml est au dossier de niveau supérieur de votre projet, vous pouvez le charger en utilisant ce code:

Application.LoadComponent(
    this, 
    new System.Uri(
    "/SLBookDemoApp;component/PagTeste2.xaml", 
    System.UriKind.Relative 
) 
); 

Si vous avez placé PagTeste2.xaml dans un sous-dossier dans votre projet (par exemple le dossier Tests) vous devez inclure le chemin vers le fichier dans l'uri:

Application.LoadComponent(
    this, 
    new System.Uri(
    "/SLBookDemoApp;component/Tests/PagTeste2.xaml", 
    System.UriKind.Relative 
) 
); 

En outre, faites très attention à l'orthographe. PagTest2.xaml est différent de PageTeste2.xaml et PageTest2.xaml. Apparemment Le test est inséré avant le et dans Page.

Vous pouvez en savoir plus sur pack URI's on MSDN.