Skip to content

Commit

Permalink
feat: modernize TemplateControl template
Browse files Browse the repository at this point in the history
  • Loading branch information
workgroupengineering committed Nov 14, 2023
1 parent 66f3823 commit 43b4664
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
36 changes: 29 additions & 7 deletions templates/csharp/templatedcontrol/NewTemplatedControl.axaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
<Styles xmlns="https://github.com/avaloniaui"
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:AvaloniaAppTemplate.Namespace">
<Design.PreviewWith>
<controls:NewTemplatedControl />

<StackPanel Width="400" MinHeight="400">
<ThemeVariantScope RequestedThemeVariant="Default">
<controls:NewTemplatedControl />
</ThemeVariantScope>
<ThemeVariantScope RequestedThemeVariant="Light">
<controls:NewTemplatedControl />
</ThemeVariantScope>
<ThemeVariantScope RequestedThemeVariant="Dark">
<controls:NewTemplatedControl />
</ThemeVariantScope>
</StackPanel>
</Design.PreviewWith>

<Style Selector="controls|NewTemplatedControl">
<!-- Set Defaults -->
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="MyForegroud" Color="Black"/>
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="MyForegroud" Color="Black"/>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="MyForegroud" Color="White"/>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

<ControlTheme x:Key="{x:Type controls:NewTemplatedControl}" TargetType="controls:NewTemplatedControl">
<Setter Property="Template">
<ControlTemplate>
<TextBlock Text="Templated Control" />
<TextBlock Text="Templated Control" Foreground="{DynamicResourceKey MyForegroud}" />
</ControlTemplate>
</Setter>
</Style>
</Styles>
</ControlTheme>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ namespace AvaloniaAppTemplate.Namespace;

public class NewTemplatedControl : TemplatedControl
{
protected override Type StyleKeyOverride =>
typeof(Avalonia.Labs.Controls.ContentDialog);
}
37 changes: 29 additions & 8 deletions templates/fsharp/templatedcontrol/NewTemplatedControl.axaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
<Styles xmlns="https://github.com/avaloniaui"
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:AvaloniaAppTemplate.Namespace">
<Design.PreviewWith>
<controls:NewTemplatedControl />
<Design.PreviewWith>
<StackPanel Width="400" MinHeight="400">
<ThemeVariantScope RequestedThemeVariant="Default">
<controls:NewTemplatedControl />
</ThemeVariantScope>
<ThemeVariantScope RequestedThemeVariant="Light">
<controls:NewTemplatedControl />
</ThemeVariantScope>
<ThemeVariantScope RequestedThemeVariant="Dark">
<controls:NewTemplatedControl />
</ThemeVariantScope>
</StackPanel>
</Design.PreviewWith>

<Style Selector="controls|NewTemplatedControl">
<!-- Set Defaults -->
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="MyForegroud" Color="Black"/>
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="MyForegroud" Color="Black"/>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="MyForegroud" Color="White"/>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

<ControlTheme x:Key="{x:Type controls:NewTemplatedControl}" TargetType="controls:NewTemplatedControl">
<Setter Property="Template">
<ControlTemplate>
<TextBlock Text="Templated Control" />
<TextBlock Text="Templated Control" Foreground="{DynamicResourceKey MyForegroud}" />
</ControlTemplate>
</Setter>
</Style>
</Styles>
</ControlTheme>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ open Avalonia.Controls.Primitives

type NewTemplatedControl () =
inherit TemplatedControl ()
override StyleKeyOverride
with get() = typedefof<NewTemplatedControl>

0 comments on commit 43b4664

Please sign in to comment.