2009-08-05 72 views
0

我有這個Page.xamlXAML頁面翻轉扭曲

<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 2009-08-06 11:07:09

0

如果PagTeste2.xaml是在你的項目的頂層文件夾,您可以使用此代碼加載:

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

如果你已經在你的項目中的子文件夾放置PagTeste2.xaml(比如文件夾Tests),你需要包含uri中文件的路徑:

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

另外,請密切注意拼寫。 PagTest2.xaml不同於PageTeste2.xamlPageTest2.xaml。顯然測試插入e頁面之前。

您可以閱讀更多關於pack URI's on MSDN