Created
June 17, 2019 09:23
-
-
Save Bloodb0ne/6aac692eb1fea9be7286020debbef670 to your computer and use it in GitHub Desktop.
Sample code for WPF Project Wizard Dialog, tried styling it like a native looking dialog but that didnt really pan out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using Microsoft.VisualStudio.TemplateWizard; | |
//using System.Windows.Forms; | |
using EnvDTE; | |
using Microsoft.VisualStudio.PlatformUI; | |
using System.Windows.Controls; | |
using System.Windows.Media; | |
using Microsoft.VisualStudio.Shell; | |
using RootTemplatePlaceholder; | |
using Microsoft.VisualStudio.Settings; | |
using Microsoft.VisualStudio.Shell.Settings; | |
using System.Windows; | |
namespace RootTemplatePlaceholder | |
{ | |
class OpenCLProjectWizard : IWizard | |
{ | |
//private UserInputForm inputForm; | |
private string customMessage; | |
public void BeforeOpeningFile(ProjectItem projectItem) | |
{ | |
} | |
public void ProjectFinishedGenerating(Project project) | |
{ | |
} | |
public void ProjectItemFinishedGenerating(ProjectItem projectItem) | |
{ | |
} | |
public void RunFinished() | |
{ | |
} | |
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) | |
{ | |
try | |
{ | |
TestWizardForm testDialog = new TestWizardForm(customMessage); | |
testDialog.ShowDialog(); | |
customMessage = testDialog.CustomMessage; | |
replacementsDictionary.Add("$custommessage$", | |
customMessage); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.ToString()); | |
} | |
} | |
public bool ShouldAddProjectItem(string filePath) | |
{ | |
return true; | |
} | |
} | |
} | |
public partial class TestWizardForm : DialogWindow | |
{ | |
private static string customMessage; | |
readonly UserControl1 testUserControl; | |
public string CustomMessage { | |
get { return customMessage; } | |
set { customMessage = value; } | |
} | |
private static SolidColorBrush ToBrush(ThemeResourceKey key) | |
{ | |
var color = VSColorTheme.GetThemedColor(key); | |
return new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B)); | |
} | |
internal TestWizardForm(string customMessage) | |
{ | |
this.IsCloseButtonEnabled = true; | |
testUserControl = new UserControl1(); | |
testUserControl.customMsgTxt.Text = customMessage; | |
this.Width = testUserControl.Width; | |
this.Height = testUserControl.Height; | |
this.Content = testUserControl.Content; | |
testUserControl.submitButton.Click += SubmitMessage; | |
this.Background = ToBrush(EnvironmentColors.EnvironmentBackgroundColorKey); | |
} | |
private void SubmitMessage(object sender,EventArgs e) | |
{ | |
customMessage = testUserControl.customMsgTxt.Text; | |
this.Close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:local="clr-namespace:RootTemplatePlaceholder" | |
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0" | |
xmlns:vsui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0" | |
xmlns:shellControls="clr-namespace:Microsoft.VisualStudio.PlatformUI.Shell.Controls;assembly=Microsoft.VisualStudio.Shell.ViewManager" | |
xmlns:Default="clr-namespace:RootTemplatePlaceholder" x:Class="RootTemplatePlaceholder.UserControl1" | |
mc:Ignorable="d" | |
Height="190" Width="532"> | |
<Grid> | |
<Grid.Resources> | |
<ResourceDictionary> | |
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Static vsfx:VsResourceKeys.ThemedDialogButtonStyleKey}}"/> | |
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Static vsfx:VsResourceKeys.ThemedDialogLabelStyleKey}}"/> | |
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Static vsfx:VsResourceKeys.TextBoxStyleKey}}"/> | |
</ResourceDictionary> | |
</Grid.Resources> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="18*"/> | |
<ColumnDefinition Width="17*"/> | |
</Grid.ColumnDefinitions> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="90"/> | |
<RowDefinition Height="70"/> | |
</Grid.RowDefinitions> | |
<StackPanel Margin="12" Grid.Row="0" Grid.ColumnSpan="2"> | |
<Label x:Name="tbDescription" HorizontalAlignment="Left" Content="Enter value for $custommessage$ parameter" Padding="0,0,0,0" Margin="7,0,0,0"/> | |
<TextBox x:Name="customMsgTxt" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Margin="7,0,0,0" Width="380"/> | |
</StackPanel> | |
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" Margin="0,12,12,12" Grid.Column="1"> | |
<Button x:Name="submitButton" Content="Set CustomMessage" Width="Auto" Height="23" Padding="6,2,6,2"/> | |
</StackPanel> | |
</Grid> | |
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
using Microsoft.VisualStudio.Shell; | |
namespace RootTemplatePlaceholder | |
{ | |
public partial class UserControl1 : UserControl | |
{ | |
public UserControl1() | |
{ | |
InitializeComponent(); | |
//submitButton.SetResourceReference(Button.StyleProperty, VsResourceKeys.ThemedDialogButtonStyleKey); | |
//customMsgTxt.SetResourceReference(TextBox.StyleProperty, VsResourceKeys.TextBoxStyleKey); | |
//tbDescription.SetResourceReference(Label.StyleProperty, VsResourceKeys.LabelEnvironmentBoldStyleKey); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment