2012-11-14 69 views
13

我想將包含xaml和cs文件以及其他目錄的文件夾添加到VS上的其他項目。由於某些原因,當我將文件夾從Windows資源管理器拖到我想放置該目錄的項目時,Visual Studio不會讓我。因爲這是我手動添加每個文件,每次遇到一個目錄我都要創建它。也許這是因爲我使用團隊基礎服務器。將現有的xaml文件添加到visual studio 2012

反正我手動添加文件,所以我點擊文件夾,我想在Visual Studio中添加文件,然後單擊添加現有文件。然後,我選擇了XAML和代碼隱藏文件:

enter image description here

當我點擊添加文件被添加,但視覺工作室不承認Bytes.xaml.cs是後面的代碼!

enter image description here

我必須手動添加窗口,然後複製並粘貼文件的內容?

回答

20

編輯您的.csproj文件,添加下面的「編譯」元素的「DependentUpon」元素爲.xaml.cs文件,以便它會出現「內部」的.xaml文件不是簡單地在它下面:

<Compile Include="BytesDisplay\SubControls\Bytes.xaml.cs"> 
    <DependentUpon>Bytes.xaml</DependentUpon> 
</Compile> 

要輕鬆編輯.csproj的文件:

Right-click the project and select "Unload Project" 
Right-click the project node again and select "Edit [projectname].csproj" 
Edit the XML, then close the file 
Right-click the project node again and select "Reload Project" 
0

感謝寫了。如果您編輯xaml和.cs文件類聲明以在沒有類衝突的情況下進行匹配 - 那麼當您添加.xaml文件時,如果它位於同一文件夾中,它將自動拾取.xaml.cs。 (vs 2013)

2

如果您將.xaml文件從Windows資源管理器拖放到Solution Explorer窗口,它將自動添加.xaml和代碼隱藏的.cs文件。

+1

這比接受的答案容易得多。如果您已經添加了這些文件,只需從項目中排除它們,然後從Windows資源管理器中拖放即可。也適用於VS 2017。 – CtrlDot

相關問題