//Create my grid and child controls
var layoutRoot = new System.Windows.Controls.Grid
{
Background = new SolidColorBrush(Colors.Blue),
Name = "layaoutRoot1",
Height = 400.0,
VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
};
layoutRoot.ColumnDefinitions.Add(new ColumnDefinition()
{
Width = new GridLength(1, GridUnitType.Auto)
});
layoutRoot.ColumnDefinitions.Add(new ColumnDefinition()
{
Width = new GridLength(1, GridUnitType.Star)
});
var myImage = new Image
{
Source = new BitmapImage(new Uri(@"C:\Path\to\Image\img.png")),
Stretch = Stretch.UniformToFill,
Margin = new Thickness(3),
Width = 50.0,
Height = 50.0,
};
var textBlocklbl = new TextBlock
{
Text = "Label Here",
FontFamily = new FontFamily("Arial"),
FontSize = 14.0,
FontWeight = FontWeights.Bold,
Margin = new Thickness(3)
};
layoutRoot.Children.Add(myImage);
layoutRoot.Children.Add(textBlocklbl);
System.Windows.Controls.Grid.SetColumn(myImage, 0);
System.Windows.Controls.Grid.SetColumn(textBlocklbl, 1);
grid1.Children.Add(layoutRoot); //grid1 is placed on the MainWindow
Storyboard myStorboard = new Storyboard();
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 0.0;
myDoubleAnimation.To = 300.0;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(3));
myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
//myDoubleAnimation.AutoReverse = true;
myStorboard.Children.Add(myDoubleAnimation);
Storyboard.SetTargetName(myDoubleAnimation, layoutRoot.Name);
Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(System.Windows.Controls.Grid.HeightProperty));
myStorboard.Begin();
回答
您的動畫無法找到動畫源。在將動畫放入邏輯樹之前,設置TargetName
將不起作用。使用StoryBoard.SetTarget(layoutRoot)
而不是StoryBoard.SetTargetName(layoutRoot.Name)
。
這裏是你可以做些什麼來解決這個問題:
1)首先你可以調試。您只需在調試模式下在Visual Studio中啓動代碼,並繼續查看Output
窗口,直到您看到錯誤。我相信你會很快看到它 - 那麼你可以修復它。您仍然有機會看不到任何錯誤。
2)其次,你應該嘗試再次調試它。把你的代碼粘貼到乾淨的解決方案中。仍然不起作用?大!繼續刪除與該問題無關的部分代碼。 VerticalAlighnment
,HorizontalAlignment
,你真的需要它們嗎?如果沒有這些屬性,問題是否可以重現?刪除它們。代碼少 - 易於調試。好吧,最後你有10行代碼,但它仍然不起作用。從MSDN正在工作,看起來儘可能接近您的樣本,找到差異。你甚至可以用MSDN替換你的代碼的一部分,看看它是否會有幫助。
3)好吧,它仍然不起作用,你還沒有找到任何樣本,你沒有辦法調試它 - 你需要社區的幫助。 正確提問。如果你是一名專業開發人員,那麼你可能已經看過很多次了 - 用戶只有一條語句it doesn't work
。你必須自己測試/調試/修復它。但那些是你的客戶,他們最終會付錢給你。這是免費的社區,只有代表我們的利益才能被驅動。如果我們不想回答你的問題 - 我們永遠不會回答你的問題。所以問一個值得回答的問題。粘貼不起作用的代碼是不夠的。您還應提供有關不起作用的部分的信息。你有什麼試圖自己修復它。如果我們認爲您試圖利用我們 - 我們不會回答您的問題。
謝謝你的時間。
UPDATE好的,只是試圖調試它。正如我所說。你的代碼給出了一個例外,layoutRoot
找不到。確切的消息是:No applicable name scope exists to resolve the name 'layaoutRoot1'.
。您只需在VS中運行您自己的代碼,就像您所說的那樣。
- 1. 不平滑DoubleAnimation
- 2. DoubleAnimation的寬度不縮小
- 3. DoubleAnimation是不更新的DependencyProperty
- 4. ScaleTransform中的DoubleAnimation
- 5. 重複DoubleAnimation是
- 6. DoubleAnimation - 旋轉圖像
- 7. 不起作用
- 8. 不起作用?
- 9. 不起作用?
- 10. 不起作用?
- 11. selenium.captureEntirePageScreenshot不起作用,但selenium.captureScreenshot起作用
- 12. ON_CALL不起作用,但EXPECT_CALL起作用
- 13. 副作用不起作用
- 14. DoubleAnimation抱怨起源==只有當NaN資源在窗口中時
- 15. 錯誤,同時增加使用DoubleAnimation是
- 16. WinRT(XAML)後面使用DoubleAnimation代碼
- 17. DoubleAnimation是使用VisualTreeHelper只能一次
- 18. StoryBoard DoubleAnimation巨大的CPU使用率
- 19. WinRT的DoubleAnimation是到Canvas.Left
- 20. WPF改變方向DoubleAnimation是
- 21. 綁定DoubleAnimation值時出錯
- 22. 如何綁定DoubleAnimation Enabled/Disabled
- 23. Document.querySelectorAll()不起作用
- 24. chart.interactiveLayer.tooltip.chartContainer不起作用?
- 25. dumpTreshold不起作用
- 26. ActionListener不起作用
- 27. suspendEvents不起作用
- 28. mysql_rollback()不起作用
- 29. RequestRouteToHost不起作用
- 30. spring.mvc.view.suffix不起作用
不知道你的問題實際上是什麼... – Tim 2011-05-26 19:07:48
有什麼問題嗎? – 2011-05-26 19:09:36
如果你需要幫助,你需要問一個問題。描述你想要什麼和錯在哪裏。 – evanb 2011-05-26 19:16:47