2008-10-21 38 views
7

Trong Visual Studio, hai tệp được tạo khi bạn tạo Biểu mẫu Windows mới trong giải pháp của mình (ví dụ: nếu bạn tạo MyForm.cs, MyForm.Designer.cs và MyForm.resx cũng được tạo). Hai tệp thứ hai này được hiển thị dưới dạng một cây con trong Solution Explorer.Tôi có thể tạo một tệp nằm bên cạnh tệp .Designer.cs trong Visual Studio không?

Có cách nào để thêm tệp vào cây con hoặc nhóm cho lớp Windows Form không?

Trả lời

14

mở csproj trong chế độ chỉnh sửa, tìm kiếm các tập tin bạn muốn được dưới một khác, và thêm các yếu tố DependentUpon, như thế này:

<Compile Include="AlertDialog.xaml.cs"> 
    <DependentUpon>AlertDialog.xaml</DependentUpon> 
</Compile> 
+0

Tiện ích FileNesting có thể tự động thực hiện điều đó: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.FileNesting – John

6

Bạn cần chỉnh sửa trực tiếp csproj. Có một thẻ DependentUpon mà bạn phải thêm dưới dạng thẻ con của tệp bạn muốn đặt trong MyForm.cs.

Ví dụ:

<Compile Include="MyForm.MyCoolSubFile.cs"> 
    <DependentUpon>MyForm.cs</DependentUpon> 
</Compile> 
4

Vâng, nhưng đó là một chút rắc rối - về cơ bản bạn cần chỉnh sửa tệp dự án bằng tay.

Dưới đây là một ví dụ từ một dự án mà Marc Gravell và tôi đều làm việc trên:

<Compile Include="Linq\Extensions\DataProducerExt.cs" /> 
<Compile Include="Linq\Extensions\DataProducerExt.SingleReturn.cs"> 
    <DependentUpon>DataProducerExt.cs</DependentUpon> 
</Compile> 
<Compile Include="Linq\Extensions\DataProducerExt.Grouping.cs"> 
    <DependentUpon>DataProducerExt.cs</DependentUpon> 
</Compile> 
<Compile Include="Linq\Extensions\DataProducerExt.Pipeline.cs"> 
    <DependentUpon>DataProducerExt.cs</DependentUpon> 
</Compile> 
<Compile Include="Linq\Extensions\DataProducerExt.Conversion.cs"> 
    <DependentUpon>DataProducerExt.cs</DependentUpon> 
</Compile> 
<Compile Include="Linq\Extensions\DataProducerExt.Math.cs"> 
    <DependentUpon>DataProducerExt.cs</DependentUpon> 
</Compile> 

Lưu ý "DependentUpon" phần tử trong mỗi phụ thuộc. Điều này hiển thị một cách thích hợp trong VS, với DataProducerExt.cs làm cha mẹ.

Các vấn đề liên quan