2011-06-22 8 views
1

私はブレンドで作られたいくつかのxamlファイルを読み込むwpfアプリケーションで作業しています。私のアプリはxamlのアニメーションを個別に実行する必要があります。私はすでに行うUserControlに構文解析し、ユーザーコントロールを作成し、stroryboardsを作成し、xamlを配置します。私の問題は、xamlから取得したアニメーションを実行できず、userControlに追加されています。xamlをロードしてアプリケーションからアニメーションを実行しようとしています

また、私はコードを配置:

private void FillMenuWindow(ScreeningArea area) 
    { 
     string lData = null; 
     bool isCanvasAdded = false; 
     UserControl menuUserControl = new UserControl(); 
     Canvas XAMLWindowCanvas = new Canvas(); 
     XDocument xmlFile = new XDocument(); 
     IEnumerable<XElement> elementList; 
     MemoryStream stream = null; 
     int initSide = 0; 
     menuStoryboardList.Clear(); 
     if (area.CurrentItem != null) 
     { 
      SimpleDelegate resumedDelegate = delegate 
      { 
       string nameCounter; 
       string myStream; 
       string mystrName; 
       xmlFile = XDocument.Load(VideoMenuSystem.DataPath + "\\" + area.CurrentItem.ItemName + ".xaml");      
       StreamReader menuReader = new StreamReader(VideoMenuSystem.DataPath + "\\" + area.CurrentItem.ItemName + ".xaml"); 

       myStream = menuReader.ReadToEnd(); 
       TextToFile(myStream, VideoMenuSystem.DataPath + "\\" + "xamlFile.txt",false); 
       menuUserControl = new UserControl(); 
       //this.RegisterName("Test", menuUserControl); 
       elementList = xmlFile.Root.Descendants();      

       foreach (XElement el in elementList) 
       { 
        mystrName = el.Name.LocalName; 
        switch (mystrName) 
        { 
         case "Storyboard": 
          lData = el.ToString(); 
          TextToFile(lData, VideoMenuSystem.DataPath + "\\" + "storyBoardFile.txt", true); 
          stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(lData)); 
          myStoryboard.Children.Add(XamlReader.Load(stream) as Storyboard);         
          break; 
         case "Canvas": 
          lData = el.ToString(); 
          if (lData != null) 
          { 
           stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(lData)); 
           XAMLWindowCanvas.Children.Add(XamlReader.Load(stream) as UIElement);          
           foreach (ScreeningArea sa in Screens) 
           { 
            if (sa == area) 
            { 
             initSide = menuSize.Width + screenSeparator; 
             break; 
            } 
           } 
           XAMLWindowCanvas.Margin = new Thickness(left, 0, 0, 0);          
           menuUserControl.Content = XAMLWindowCanvas; 
           left += initSide; 
          } 
          isCanvasAdded = true; 
          break; 
        } 
        if (isCanvasAdded) 
         break; 
       } 
       nameCounter = DateTime.Now.Ticks.ToString(); 
       String myNameCounter = nameCounter.Substring(nameCounter.Length - 10); 
       menuUserControl.Resources.Add("SB_" + myNameCounter, myStoryboard); 
       menuStoryboardList.Add(myStoryboard); 
       playbackArea.Children.Add(menuUserControl); 
       playbackArea.Loaded += new RoutedEventHandler(fireAnimation);      
      }; 
      Dispatcher.BeginInvoke(resumedDelegate); 
     } 
    } 

答えて

0

私は、彼らが同じスコープ内ではありません、私のユーザーコントロールにストーリーボードやキャンバスを追加していたときに問題がなぜストーリーボードがオブジェクトを見つけることができないということであることを考え出しましたアニメートする。注文して修正しようとしたコードを書き直しますが、成功しません!これは新しいコードです:

private UserControl ReadMenuObj(ScreeningArea area) 
{ 
    bool isCanvasAdded = false; 
    int initSide = 0; 
    string myStream; 
    string mystrName; 
    string nameCounter; 
    string lData = null; 
    UserControl localUC = new UserControl(); 
    XDocument xmlFile = new XDocument(); 
    Storyboard localSB = new Storyboard(); 
    Canvas XAMLWindowCanvas = new Canvas(); 
    IEnumerable<XElement> elementList; 
    StreamReader menuReader; 
    MemoryStream stream = null; 

    xmlFile = XDocument.Load(VideoMenuSystem.DataPath + "\\" + area.CurrentItem.ItemName + ".xaml"); 
    menuReader = new StreamReader(VideoMenuSystem.DataPath + "\\" + area.CurrentItem.ItemName + ".xaml"); 

    myStream = menuReader.ReadToEnd(); 
    TextToFile(myStream, VideoMenuSystem.DataPath + "\\" + "xamlFile.txt", false); 
    elementList = xmlFile.Root.Descendants(); 

    myStoryboard = new Storyboard(); 
    foreach (XElement el in elementList) 
    { 
     mystrName = el.Name.LocalName; 
     switch (mystrName) 
     { 
      case "Storyboard": 
       lData = el.ToString(); 
       TextToFile(lData, VideoMenuSystem.DataPath + "\\" + "storyBoardFile.txt", true); 
       stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(lData)); 
       localSB = XamlReader.Load(stream) as Storyboard; 
       for (int i = 0; i < localSB.Children.Count; i++) 
       { 
        Timeline tm = (Timeline)localSB.Children.ElementAt(i); 
        myStoryboard.Children.Add(tm); 
       } 
       //myStoryboard.Children.Add(localSB); 
       break; 
      case "Canvas": 
       lData = el.ToString(); 
       XAMLWindowCanvas = new Canvas(); 
       if (lData != null) 
       { 
        TextToFile(lData, VideoMenuSystem.DataPath + "\\" + "xamlFile2.txt", true); 
        stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(lData)); 
        DependencyObject rootObject = XamlReader.Load(stream) as DependencyObject; 
        XAMLWindowCanvas = rootObject as Canvas; 
        //XAMLWindowCanvas.Children.Add(XamlReader.Load(stream) as UIElement); 
        foreach (ScreeningArea sa in Screens) 
        { 
         if (sa == area) 
         { 
          initSide = menuSize.Width + screenSeparator; 
          break; 
         } 
        } 
        XAMLWindowCanvas.Margin = new Thickness(left, 0, 0, 0); 
        //XAMLWindowCanvas.Loaded += new RoutedEventHandler(fireAnimation); 
        XAMLWindowCanvas.MouseDown += new MouseButtonEventHandler(fireAnimation); 
        localUC.Content = XAMLWindowCanvas; 
        int cnvConut = XAMLWindowCanvas.Children.Count; 
        left += initSide; 
       } 
       isCanvasAdded = true; 
       break; 
     } 
     if (isCanvasAdded) 
      break; 
    } 
    menuStoryboardList.Add(myStoryboard); 
    nameCounter = DateTime.Now.Ticks.ToString(); 
    String myNameCounter = nameCounter.Substring(nameCounter.Length - 10); 
    localUC.Resources.Add("SB_" + myNameCounter, myStoryboard); 
    Canvas cnv = (Canvas)localUC.FindName("Combo_3"); 
    Storyboard storyboard = (Storyboard)localUC.Resources["CombonAnim"]; 
    return localUC; 
} 
関連する問題