Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

x:Static XAMLIL compiler error

Open aguahombre opened this issue 4 years ago • 8 comments

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.

aguahombre avatar Apr 08 '20 08:04 aguahombre

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 avatar Jul 30 '22 21:07 topeterk

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

topeterk avatar Jul 30 '22 21:07 topeterk

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

maxkatz6 avatar Jul 30 '22 21:07 maxkatz6

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

topeterk avatar Jul 30 '22 21:07 topeterk

@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.

maxkatz6 avatar Jul 30 '22 21:07 maxkatz6

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)

topeterk avatar Jul 30 '22 22:07 topeterk

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

maxkatz6 avatar Jul 30 '22 22:07 maxkatz6

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)

topeterk avatar Jul 30 '22 22:07 topeterk

@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>

tisis2 avatar Sep 01 '23 06:09 tisis2