VS2013 图片背景·全透明背景图(转)
生活随笔
收集整理的這篇文章主要介紹了
VS2013 图片背景·全透明背景图(转)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Note:
1.xaml編輯器和個別的編輯器(如HTML的)因為是承載在VS的一個子窗口上,所以背景依然是黑色的。
2.該背景必須在VS實驗環(huán)境下使用。
效果圖:
1.準備工作
1.先準備Visual Studio 2013 SDK
http://download.microsoft.com/download/9/1/0/910EE61D-A231-4DAB-BD56-DCE7092687D5/vssdk_full.exe
2.可直接套用的VSTheme
http://pan.baidu.com/s/1kTFt3gz
2.新建Package項目
1.安裝好SDK后,進入VS。先新建一個Project,在“其它項目類型”那里找到“Visual Studio Package”
2.接下來的對話框里,選“C#”,然后基本是下一步。在最后一步把那兩個復選框取消,因為那個在這里沒什么用處。最后就成功新建了個VS擴展的Project
3.對Project添加WPF的程序集為引用,有四個,分別為“PresentationCore”、“PresentationFramework”、“System.Xaml”、“WindowsBase”。
4.然后打開“XXXPackage.cs”(XXX一般為這個Project的名字)文件,
代碼如下:
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Microsoft.SoheeBackground//命名空間自己修改回自己用的
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112","1.0", IconResourceID = 400)]
//此處刪除了一條代碼段,原因不明,對后續(xù)影響不明
[ProvideAutoLoad(UIContextGuids.NoSolution)]
[ProvideAutoLoad(UIContextGuids.SolutionExists)]
public sealed class IDEBackgroundPackage : Package
{
protected override void Initialize()
{
base.Initialize();
Application.Current.MainWindow.Loaded += MainWindow_Loaded;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var rWindow = (Window)sender;
//加載圖片 E:FileDownloadExplorere30870a304e251ff3c5926fa786c9177f3e537f.jpg
var rImageSource = BitmapFrame.Create(new Uri(@"E:FileDownloadExplorer241f95cad1c8a786d814d6eb6709c93d70cf501c.jpg"/*圖片路徑*/), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
rImageSource.Freeze();
var rImageControl = new Image()
{
Source = rImageSource,
Stretch =Stretch.UniformToFill, //按比例填充
HorizontalAlignment =HorizontalAlignment.Center, //水平方向中心對齊
VerticalAlignment =VerticalAlignment.Center, //垂直方向中心對齊
};
Grid.SetRowSpan(rImageControl, 4);
var rRootGrid =(Grid)rWindow.Template.FindName("RootGrid", rWindow);
rRootGrid.Children.Insert(0, rImageControl);
}
}
}
5.代碼修改后,調試,這時就會編譯擴展,然后啟動實驗用VS。(如果這是第一次啟動實驗用VS,可能要像剛安裝完VS那樣設置一下)接著你會看到角落處顯現(xiàn)出那張背景圖
3.修改皮膚配色
1.關閉實驗用VS,前往官網(wǎng)下載并安裝Visual Studio 2013 Color Theme Editor
https://visualstudiogallery.msdn.microsoft.com/9e08e5d3-6eb4-4e73-a045-6ea2a5cbdabe
2.安裝成功后,重啟VS,并調試啟動實驗用VS
3.此時在實驗用VS中搜索并按照Color Theme
4.重啟,重啟后,進入“工具->CustomizeColors”。在“Customize Colors”那里點“Import Theme”即可(文件在一開始百度云下載的打包文件中)
4.編輯器透明化
1.到目前為止,打開文件后,編輯器的背景還是黑的。接下來就是把這層黑的去掉。先打開“source.extension.vsixmanifest”文件,進入“Assets”選項卡,單擊“New”按鈕。在彈出的對話框里,“Type”選“Microsoft.VisualStudio.MefComponent”,“Source”選“Aproject in current solution”,“Project”選當前的Project,目前應該就一個選項的。最后OK
2.添加引用System.ComponentModel.Composition、Microsoft.VisualStudio.CoreUtility、Microsoft.VisualStudio.Text.UI、Microsoft.VisualStudio.Text.UI.Wpf
3.新建一個文件,這里就叫“EditorBackground.cs”
代碼如下:
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
using System;
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
namespace Microsoft.SoheeBackground
{
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("Text")]
[ContentType("BuildOutput")]
[TextViewRole(PredefinedTextViewRoles.Document)]
class Listener :IWpfTextViewCreationListener
{
[Import]
IEditorFormatMapService EditorFormatMapService = null;
public void TextViewCreated(IWpfTextView rpTextView)
{
new EditorBackground(rpTextView);
//去掉斷點邊欄的背景
var rProperties = EditorFormatMapService.GetEditorFormatMap(rpTextView).GetProperties("IndicatorMargin");
rProperties["BackgroundColor"] = Colors.Transparent;
rProperties["Background"]= Brushes.Transparent;
}
}
class EditorBackground
{
IWpfTextView r_TextView;
ContentControl r_Control;
Grid r_ParentGrid;
Canvas r_ViewStack;
public EditorBackground(IWpfTextView rpTextView)
{
r_TextView = rpTextView;
r_Control =(ContentControl)r_TextView;
r_TextView.Background =Brushes.Transparent;
r_TextView.BackgroundBrushChanged+= TextView_BackgroundBrushChanged;
r_TextView.Closed +=TextView_Closed;
r_Control.Loaded += TextView_Loaded;
}
void MakeBackgroundTransparent()
{
r_TextView.Background =Brushes.Transparent;
r_ViewStack.Background =Brushes.Transparent;
r_ParentGrid.ClearValue(Grid.BackgroundProperty);
}
void TextView_Loaded(object sender,RoutedEventArgs e)
{
if (r_ParentGrid == null)
r_ParentGrid =(Grid)r_Control.Parent;
if (r_ViewStack == null)
r_ViewStack = (Canvas)r_Control.Content;
MakeBackgroundTransparent();
}
void TextView_BackgroundBrushChanged(object sender, BackgroundBrushChangedEventArgs e)
{
r_Control.Dispatcher.BeginInvoke(new Action(() =>
{
while (r_ParentGrid.Background != null)
MakeBackgroundTransparent();
}), DispatcherPriority.Render);
}
void TextView_Closed(object sender,EventArgs e)
{
//清除委托,以防內存泄露
r_TextView.Closed -=TextView_Closed;
r_TextView.BackgroundBrushChanged-= TextView_BackgroundBrushChanged;
}
}
}
4.再啟動調試用VS,選擇之前Import 的 Theme即可。
5.以后可以直接在 開始-VisualStudio2013-Microsoft VisualStudio SDK-Tools-Start Experimental Instance 開啟調試用VS
PS:參考
1.http://startalkers.lofter.com/post/1cb119b5_5be5e5a
2.http://doc.okbase.net/u012915516/archive/124296.html
來自為知筆記(Wiz)
總結
以上是生活随笔為你收集整理的VS2013 图片背景·全透明背景图(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高通V2X开发平台构成与成本分析
- 下一篇: js 嵌入php_PHP快速入门第一讲: