Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modernize TemplateControl template #239

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we should have this in the templates.
I would rather add a comment with a link to the Avalonia.Samples, where we would have this.


<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
workgroupengineering marked this conversation as resolved.
Show resolved Hide resolved
with get() = typedefof<NewTemplatedControl>