Skip to content

Commit 64d647c

Browse files
committed
Added an example of how to extend the styles.
1 parent 972bef0 commit 64d647c

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<platform:DialogWindow
2+
x:Class="TestExtension.CustomizedStylesDialog"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:platform="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
8+
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
9+
xmlns:shell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
10+
mc:Ignorable="d"
11+
d:DesignHeight="450"
12+
d:DesignWidth="800"
13+
toolkit:Themes.UseVsTheme="True"
14+
Width="300"
15+
Height="400"
16+
Title="Customized Styles"
17+
WindowStartupLocation="CenterOwner"
18+
ShowInTaskbar="False"
19+
>
20+
21+
<Window.Resources>
22+
<ResourceDictionary>
23+
<!--
24+
To customize a style provided by the toolkit, you need to make the resources
25+
available by including the resource dictionary from the toolkit:
26+
-->
27+
<ResourceDictionary.MergedDictionaries>
28+
<ResourceDictionary Source="{x:Static toolkit:ToolkitResourceKeys.ThemeResourcesUri}"/>
29+
</ResourceDictionary.MergedDictionaries>
30+
31+
<!--
32+
Now you can create your own styles that are based on the toolkit's styles.
33+
-->
34+
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Static toolkit:ToolkitResourceKeys.TextBoxStyleKey}}">
35+
<Setter Property="BorderBrush" Value="Red" />
36+
</Style>
37+
38+
<!--
39+
The toolkit only defines a few customized styles. Most styles come from the default Visual Studio
40+
styles. These can be referenced using the keys from `Microsoft.VisualStudio.Shell.VsResourceKeys`.
41+
-->
42+
<Style TargetType="Button" BasedOn="{StaticResource {x:Static shell:VsResourceKeys.ThemedDialogButtonStyleKey}}">
43+
<Setter Property="Foreground" Value="Green" />
44+
</Style>
45+
</ResourceDictionary>
46+
</Window.Resources>
47+
48+
<StackPanel Orientation="Vertical" Margin="10">
49+
<TextBox
50+
Text="This TextBox uses the style from the toolkit, but extends it to have a red border."
51+
AcceptsReturn="True"
52+
Height="50"
53+
TextWrapping="Wrap"
54+
/>
55+
56+
<Button
57+
Content="Green text on a button"
58+
Margin="0,10,0,0"
59+
/>
60+
</StackPanel>
61+
</platform:DialogWindow>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.VisualStudio.PlatformUI;
2+
3+
namespace TestExtension
4+
{
5+
public partial class CustomizedStylesDialog : DialogWindow
6+
{
7+
public CustomizedStylesDialog()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+
}

demo/VSSDK.TestExtension/ToolWindows/ThemeWindow/ThemeWindowControl.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<ColumnDefinition Width="Auto"/>
2525
<ColumnDefinition Width="*"/>
2626
<ColumnDefinition Width="Auto"/>
27+
<ColumnDefinition Width="Auto"/>
2728
</Grid.ColumnDefinitions>
2829

2930
<StackPanel
@@ -56,6 +57,14 @@
5657
Content="Open Dialog"
5758
Command="{Binding OpenDialogCommand}"
5859
VerticalAlignment="Center"
60+
Margin="10,0"
61+
/>
62+
63+
<Button
64+
Grid.Column="3"
65+
Content="Customized Styles"
66+
Command="{Binding OpenCustomStylesCommand}"
67+
VerticalAlignment="Center"
5968
/>
6069
</Grid>
6170

demo/VSSDK.TestExtension/ToolWindows/ThemeWindow/ThemeWindowControlViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public bool UseVsTheme
6464

6565
#pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed
6666
public ICommand OpenDialogCommand => new DelegateCommand(() => OpenDialog());
67+
public ICommand OpenCustomStylesCommand => new DelegateCommand(() => OpenCustomStyles());
6768
#pragma warning restore VSTHRD012 // Provide JoinableTaskFactory where allowed
6869

6970
private void OpenDialog()
@@ -72,6 +73,12 @@ private void OpenDialog()
7273
dialog.ShowModal();
7374
}
7475

76+
private void OpenCustomStyles()
77+
{
78+
CustomizedStylesDialog dialog = new CustomizedStylesDialog();
79+
dialog.ShowModal();
80+
}
81+
7582
private async Task ApplyThemeAsync(Theme theme)
7683
{
7784
// There doesn't appear to be a way to set the theme programatically,

demo/VSSDK.TestExtension/VSSDK.TestExtension.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
<DependentUpon>RunnerWindowControl.xaml</DependentUpon>
8080
</Compile>
8181
<Compile Include="ToolWindows\RunnerWindowMessenger.cs" />
82+
<Compile Include="ToolWindows\ThemeWindow\CustomizedStylesDialog.xaml.cs">
83+
<DependentUpon>CustomizedStylesDialog.xaml</DependentUpon>
84+
</Compile>
8285
<Compile Include="ToolWindows\ThemeWindow\ThemedControl.cs" />
8386
<Compile Include="ToolWindows\ThemeWindow\ThemeWindow.cs" />
8487
<Compile Include="ToolWindows\ThemeWindow\ThemeWindowControl.xaml.cs">
@@ -141,6 +144,10 @@
141144
<SubType>Designer</SubType>
142145
<Generator>MSBuild:Compile</Generator>
143146
</Page>
147+
<Page Include="ToolWindows\ThemeWindow\CustomizedStylesDialog.xaml">
148+
<SubType>Designer</SubType>
149+
<Generator>MSBuild:Compile</Generator>
150+
</Page>
144151
<Page Include="ToolWindows\ThemeWindow\ThemedControl.xaml">
145152
<SubType>Designer</SubType>
146153
<Generator>MSBuild:Compile</Generator>

0 commit comments

Comments
 (0)