AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.05k stars 2.25k forks source link

x:Static XAMLIL compiler error #3759

Closed aguahombre closed 1 year ago

aguahombre commented 4 years ago

Avalonia 0.9.7 throws an error in XAMLIL compiler for the following.

<x:Static x:Key="HidePasswordChar" Member="v:MyView.HidePasswordChar"/>

Avalonia error XAMLIL: x:Static extension should take exactly one constructor parameter without any content OR Member property

This works in WPF.

topeterk commented 2 years ago

I saw this with Avalonia 0.10.14 as well: CSC : error AXN0002: XamlX.XamlParseException: x:Static extension should take exactly one constructor parameter without any content OR Member property
However, not sure if this has anything in common but when I keep using xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" instead of xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" it throws CSC : error AXN0002: XamlX.XamlParseException: Unable to resolve type Static from namespace http://schemas.microsoft.com/winfx/2009/xaml instead.
With 2006 and 2009 scheme my origin project using Xamarin works fine.

topeterk commented 2 years ago

PS: A failing example: {x:Static common:Statics.GlobalHotKeySupport, Mode=OneTime} It seems so far temporary working fix: {x:Static common:Statics.GlobalHotKeySupport}

maxkatz6 commented 2 years ago

@topeterk What's point of using "Mode=OneTime" on a static markup extension? It's always static, i.e. always onetime.

topeterk commented 2 years ago

I learned somewhere from a Xamarin/XAML best-practice advice that the Bindings should be as strict as possible as it spares runtime and memory that would be needed for creating a two directional runtime binding. So with OneTime there is no binding in the write direction and there is also no "runtime" binding, as it executes only once and will never update later on. @maxkatz6

maxkatz6 commented 2 years ago

@topeterk that's right, better to keep bindings strict. But "x:Static" is not a binding. It's just a static reference. There is no point in a binding mode here.

topeterk commented 2 years ago

Ah okay, I thought it is like a "Binding" but just to indicate it is a static source/target and must be handled differently internally. But when it actually is something different that yes, I can understand that.

Do you also know why it is failing when I am using a newer scheme reference? (Even when the produced error is not the same question as of this issue)

maxkatz6 commented 2 years ago

No, it might be a compiler issue, if it's supposed to work by xaml specs https://github.com/kekekeks/XamlX

topeterk commented 2 years ago

Thanks for your help, @maxkatz6

I created an issue there for the schema version issue: https://github.com/kekekeks/XamlX/issues/64 (just as reference)

tisis2 commented 1 year ago

@kekekeks what about the original issue, that points out that x:static is not usable as a tag... im facing the same currently... how could i use static reference when i cannot use a markup?

my example currently is that i have an element in xaml that takes a enumerable as content and i want to fill them from some static values... i cant fill an enumerable from markup so i have to do something like (at least i am used to that from wpf):

<EnumerableOwner>
    <x:Static Member="FOO"/>
    <x:Static Member="FOO2"/>
</EnumerableOwner>