2009-08-05 5 views
0

私はこのPage.xamlをを持ってXAMLページフリップツイスト

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

とコレス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); 
     } 
    } 
} 

そして、私は含めることwnat XAMLは、この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> 
特派付き

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. 
     } 
    } 
} 

私は

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

誰もが知っている、なぜこの行にエラーを取得していますか?

答えて

0

使用この代わりには:

this.Content = new PagTeste2(); 

あなただけが別のアセンブリからコンテンツをロードしているとさえ、あなたはコンテンツを設定するためにそれを使用しないならば、アセンブリのロードの任意の並べ替えを行う必要があります。

実際にどのようにアセンブリを動的にロードするかを尋ねる場合は、MS have an example of how

0

/SLBookDemoApp;component/PageTeste2.xamlを試してみるとよいでしょう。

+0

私はすでにそれを試みましたが、動作しませんでした。 これをどのように動作させることができますか? – Bonfocchi

0

PagTeste2.xamlは、プロジェクトの最上位レベルのフォルダにある場合は、このコード使用してそれを読み込むことができます:あなたのプロジェクト内のサブフォルダにPagTeste2.xamlを配置した場合

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

を(フォルダTestsを言う)あなたがする必要がありますファイルのパスをuriに含める:

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

また、スペルに注意してください。 PagTest2.xamlPageTeste2.xamlおよびPageTest2.xamlとは異なります。明らかに試験は、eの前に挿入され、ページの前に挿入されます。

pack URI's on MSDNについて詳しく読むことができます。