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 3 commits
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
26 changes: 18 additions & 8 deletions templates/csharp/templatedcontrol/NewTemplatedControl.axaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<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">

<!--
If you want support Theme variant see
Docs: https://docs.avaloniaui.net/docs/basics/user-interface/styling/control-themes
https://docs.avaloniaui.net/docs/guides/styles-and-resources/how-to-use-theme-variants
Sample: https://github.com/AvaloniaUI/Avalonia.Samples/tree/main/src/Avalonia.Samples/CustomControls/RatingControlSample#step-9-theme-variant
-->
workgroupengineering marked this conversation as resolved.
Show resolved Hide resolved
<Design.PreviewWith>
<controls:NewTemplatedControl />
<StackPanel Width="400" Spacing="10">
<StackPanel Background="{DynamicResource SystemRegionBrush}">
<controls:NewTemplatedControl />
</StackPanel>
</StackPanel>
</Design.PreviewWith>

<Style Selector="controls|NewTemplatedControl">
<!-- Set Defaults -->

<ControlTheme x:Key="{x:Type controls:NewTemplatedControl}" TargetType="controls:NewTemplatedControl">
<Setter Property="Template">
<ControlTemplate>
<TextBlock Text="Templated Control" />
<TextBlock Text="Templated Control" Foreground="{TemplateBinding Foreground}" />
</ControlTemplate>
Copy link
Member

Choose a reason for hiding this comment

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

Why Foreground is here? It's an inherited property. In Avalonia controls we try to avoid redefining this property, where it can be inherited.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just an indication for beginners of how it might be done.

</Setter>
</Style>
</Styles>
</ControlTheme>
</ResourceDictionary>
26 changes: 18 additions & 8 deletions templates/fsharp/templatedcontrol/NewTemplatedControl.axaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<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">

<!--
If you want support Theme variant see
Docs: https://docs.avaloniaui.net/docs/basics/user-interface/styling/control-themes
https://docs.avaloniaui.net/docs/guides/styles-and-resources/how-to-use-theme-variants
Sample: https://github.com/AvaloniaUI/Avalonia.Samples/tree/main/src/Avalonia.Samples/CustomControls/RatingControlSample#step-9-theme-variant
-->
<Design.PreviewWith>
<controls:NewTemplatedControl />
<StackPanel Width="400" Spacing="10">
<StackPanel Background="{DynamicResource SystemRegionBrush}">
<controls:NewTemplatedControl />
</StackPanel>
</StackPanel>
</Design.PreviewWith>

<Style Selector="controls|NewTemplatedControl">
<!-- Set Defaults -->

<ControlTheme x:Key="{x:Type controls:NewTemplatedControl}" TargetType="controls:NewTemplatedControl">
<Setter Property="Template">
<ControlTemplate>
<TextBlock Text="Templated Control" />
<TextBlock Text="Templated Control" Foreground="{TemplateBinding Foreground}" />
</ControlTemplate>
</Setter>
</Style>
</Styles>
</ControlTheme>
</ResourceDictionary>
Loading