[英]How to display (transparent) animated gif in a Visual Studio extension panel?
我正在用C#開發Visual Studio擴展,並且我想在工具窗口面板內顯示(正在等待)透明的gif動畫。
我已經在Google上搜索了很多東西,但我只能找到非常復雜的解決方案,其中涉及要添加到我的項目中的專用庫或一些等效的源代碼。 例如,我可以找到這篇文章: 如何獲得動畫gif在WPF中工作? 。 但是我不明白為什么對於動畫gifs這樣的基本功能需要復雜的解決方案。
XAML無法支持本地動畫gif嗎?
就我而言,我在XAML文件中嘗試了以下操作:
<Image Source="pack://application:,,,/MyPlugin;component/Resources/busy.gif"
Width="16" Height="16"/>
在Visual Studio處於編輯模式下時,圖像會加載(盡管不是動畫)。 但是,該圖像從不在實驗實例中顯示。
我錯過了什么?
例如,我可以找到這篇文章:如何獲得動畫gif在WPF中工作? 但是我不明白為什么對於動畫gifs這樣的基本功能需要復雜的解決方案。
有一些簡單的方法可以在wpf中顯示.gif。 對我來說,我使用WpfAnimatedGif來做到這一點,只需安裝nuget包並添加相應的xmlns,然后gif就可以以wpf或vs擴展名顯示。
對於WpfAnimatedGif
:
1.將xmlns:gif="http://wpfanimatedgif.codeplex.com"
到xx.xaml。
2. <Image gif:ImageBehavior.AnimatedSource="xxx/xxx.gif" />
然后,.gif可以顯示在vs擴展名中。
The format in my project:
<UserControl x:Class="VSIXProject2.ToolWindow1Control"
...
xmlns:gif="http://wpfanimatedgif.codeplex.com"
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Name="MyToolWindow">
<Grid>
<StackPanel Orientation="Vertical">
...
<Image gif:ImageBehavior.AnimatedSource="pack://application:,,,/VSIXProject2;component/Resources/time.gif" Height="100" Width="200"/>
</StackPanel>
</Grid>
</UserControl>
注意:要在調試VS擴展時顯示圖像,源格式應為pack://application:,,,/xxx;component/Resources/xxx.gif
。 vsix中普通wpf和ToolWindows之間的行為不同。 更多細節請看這里 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.