Skip to content

Commit

Permalink
Update C# templates to introduce file scoped namespaces (#4911)
Browse files Browse the repository at this point in the history
* Update C# templates to introduce file scoped namespaces

* introduce file scoped namespaces to dev/VSIX/Extension and dev/VSIX/Shared folders as well

* resolve comments:
1. mark all classes 'partial'
2. align the MainWindow to be an empty Grid without the Button and handler

* Enable Mica

* remove mica for non-window level

* 1. Remove 'Button' from C++ templates
2. Remove Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" from Blank Page item template

* 1. Remove 'this.' and change 'm_' to '_'
2. Add empty line between functions

* revert file scoped namesapce for VSPackages.cs and WizardImplementation.cs

---------

Co-authored-by: Haonan Tang (from Dev Box) <[email protected]>
  • Loading branch information
haonanttt and Haonan Tang (from Dev Box) authored Dec 17, 2024
1 parent 16f4ec2 commit a0a435d
Show file tree
Hide file tree
Showing 34 changed files with 180 additions and 215 deletions.
4 changes: 2 additions & 2 deletions dev/VSIX/Extension/Cs/Dev17/VSPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace WindowsAppSDK.Cs.Extension
/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(VSPackage.PackageGuidString)]
public sealed class VSPackage : AsyncPackage
public sealed partial class VSPackage : AsyncPackage
{
/// <summary>
/// VSPackage GUID string.
Expand All @@ -55,4 +55,4 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke

#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
mc:Ignorable="d"
Title="$itemname$">

<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>

<Grid>

</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $rootnamespace$
namespace $rootnamespace$;

/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class $safeitemname$ : Window
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class $safeitemname$ : Window
public $safeitemname$()
{
public $safeitemname$()
{
this.InitializeComponent();
}
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ namespace winrt::$rootnamespace$::implementation
{
throw hresult_not_implemented();
}

void $safeitemname$::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
myButton().Content(box_value(L"Clicked"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace winrt::$rootnamespace$::implementation

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
mc:Ignorable="d"
Title="$itemname$">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Grid>

</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
xmlns:local="using:$rootnamespace$"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
mc:Ignorable="d">

<Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $rootnamespace$
namespace $rootnamespace$;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class $safeitemname$ : Page
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class $safeitemname$ : Page
public $safeitemname$()
{
public $safeitemname$()
{
this.InitializeComponent();
}
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $rootnamespace$
namespace $rootnamespace$;

public sealed partial class $safeitemname$ : Control
{
public sealed class $safeitemname$ : Control
public $safeitemname$()
{
public $safeitemname$()
{
this.DefaultStyleKey = typeof($safeitemname$);
}
DefaultStyleKey = typeof($safeitemname$);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $rootnamespace$
namespace $rootnamespace$;

public sealed partial class $safeitemname$ : UserControl
{
public sealed partial class $safeitemname$ : UserControl
public $safeitemname$()
{
public $safeitemname$()
{
this.InitializeComponent();
}
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ namespace winrt::$rootnamespace$::implementation
{
throw hresult_not_implemented();
}

void $safeitemname$::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
myButton().Content(box_value(L"Clicked"));
}
}
2 changes: 0 additions & 2 deletions dev/VSIX/ItemTemplates/Neutral/CppWinRT/BlankPage/BlankPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace winrt::$rootnamespace$::implementation

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Grid>

</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ namespace winrt::$rootnamespace$::implementation
{
throw hresult_not_implemented();
}

void $safeitemname$::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
myButton().Content(box_value(L"Clicked"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace winrt::$rootnamespace$::implementation

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Grid>

</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $safeprojectname$
namespace $safeprojectname$;

public partial class Class1
{
public class Class1
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $safeprojectname$
namespace $safeprojectname$;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
private Window? _window;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public partial class App : Application
public App()
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}
InitializeComponent();
}

private Window? m_window;
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
_window = new MainWindow();
_window.Activate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
mc:Ignorable="d"
Title="$projectname$">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>

<Grid>

</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $safeprojectname$
namespace $safeprojectname$;

/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
public MainWindow()
{
public MainWindow()
{
this.InitializeComponent();
}

private void myButton_Click(object sender, RoutedEventArgs e)
{
myButton.Content = "Clicked";
}
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $safeprojectname$
namespace $safeprojectname$;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
private Window? _window;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public partial class App : Application
public App()
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}
InitializeComponent();
}

private Window? m_window;
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
_window = new MainWindow();
_window.Activate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
mc:Ignorable="d"
Title="$projectname$">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>

<Grid>

</Grid>
</Window>
Loading

0 comments on commit a0a435d

Please sign in to comment.