question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken attached property detection with `AddOwner` usage

See original GitHub issue

Describe the bug After recent text processing changes TextBlock attached properties have been moved to TextElement. One would expect that old code using TextBlock properties will fail to compile so it can be fixed. But this is not the case and many invalid usages work fine.

To Reproduce

<Window.Styles>
  <Style Selector="ContentPresenter">
    <Setter Property="TextBlock.FontWeight" Value="Normal" />
  </Style>
</Window.Styles>
  
<StackPanel>
  <ContentPresenter TextBlock.FontWeight="{DynamicResource ComboBoxHeaderThemeFontWeight}" />
  <ContentPresenter TextBlock.FontWeight="Normal" />
</StackPanel>

Usage in style setter - works fine Usage with a dynamic resource or binding - works fine Usage with a raw value - compilation error

Expected behavior I would expect all cases above to error out since this is no longer an attached property (not sure about selector though) on TextBlock.

After a quick check in the compiler it seems that this property is detected as an attached property since property type name does not contain Attached. https://github.com/AvaloniaUI/Avalonia/blob/master/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs#L45

AddOwner on an attached property is supposed to convert it to a regular styled property I think but since property analysis is static it is not picked up. But even in runtime one cannot tell if this a converted attached property since original attached property is returned. https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/AttachedProperty.cs#L39

I think that user code will struggle a lot with random compilation errors caused by text breaking change until this issue gets resolved.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
MarchingCubecommented, Apr 5, 2022

My worry is coming from that my project has tons of code like: image

This seems to work for now. Now somebody changes one value to a non-binding.

image

And you get an interesting error message:

image

Which claims that one cannot set FontSize on a TextBlock.

0reactions
grokyscommented, May 30, 2022

Spoken privately with @MarchingCube and this problem was caused by referencing a stale assembly. Keeping the issue open though because in investigating the problem I found a slight discrepancy on how attached properties are resolved. PR incoming.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency Properties | WPF Fundamentals
Dependency Properties. WPF introduces a type of property called a dependency property that is used throughout the platform to enable styling ...
Read more >
How do dependency/attached properties work internally ...
Does AddOwner method call on Attached property assigns value to the instance field? When does this happen and where does the value go?...
Read more >
Attached properties - .NET MAUI
NET MAUI attached properties enable an object to assign a value for a property that its own class doesn't define.
Read more >
Activities - Web Detection
This activity searches the web for images that match the specified image. Propertieslink. Common. ContinueOnError - If set, the remaining activities are ...
Read more >
Break Element
The key-ins TRIM BREAK BYTWOPOINTS RETAINGEOMETRY and TRIM BREAK BYTWOPOINTS RETAINPOINTS control how the curves are retained when you use the tool for ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found