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

Strongly-typed inline styles #254

Merged
merged 5 commits into from
Jun 14, 2024
Merged

Conversation

h0lg
Copy link
Contributor

@h0lg h0lg commented Jun 6, 2024

This PR enables adding inline IStyle instances to any StyledElement, allowing you to write styles in a strongly-typed manner without .xaml files - even down to the selectors.

let private coloredTextBoxWatermark (color: IBrush) =
    let style = Style(_.OfType<TextBox>().Template().OfType<TextBlock>().Name("PART_Watermark"))
    style.Setters.Add(Setter(Avalonia.Controls.TextBlock.ForegroundProperty, box color))
    style

let view () =
    AutoCompleteBox([]).inlineStyles(coloredTextBoxWatermark(Brushes.Crimson))

It includes

  • an example that uses the new extension to style an AutoCompleteBox in a way that neither the Fabulous nor Avalonia API would otherwise allow for.
  • an unrelated fix for the focusing of AutoCompleteBoxes in the EditableTreeView example.

src/Fabulous.Avalonia/Views/_StyledElement.fs Outdated Show resolved Hide resolved
src/Fabulous.Avalonia/Views/_StyledElement.fs Outdated Show resolved Hide resolved
samples/Gallery/Pages/StylesPage.fs Outdated Show resolved Hide resolved
Copy link
Member

@edgarfgp edgarfgp left a comment

Choose a reason for hiding this comment

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

Thanks for this. Really appreciate all your contributions.

@edgarfgp edgarfgp merged commit 5679f10 into fabulous-dev:main Jun 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants