serg046 / eventbinder Goto Github PK
View Code? Open in Web Editor NEWAllows binding a method to any WPF/Avalonia event
License: MIT License
Allows binding a method to any WPF/Avalonia event
License: MIT License
It's said in getting started:
Just install the nuget package. If it does not work and you get XamlParseException, then apply [assembly: EventBinder.AssemblyReference] attribute in your AssemblyInfo.cs.
Ok, I have the Exception, and, that's all. How can I add this assembly reference ? Maybe related to #59. If so, I will wait then.
Thanks.
Edited for more Info:
xmlns:e="using:EventBinder" works. But Exception at {e:EventBinding...}
'Could not load file or assembly 'Avalonia.Visuals, Version=0.9.12.0, Culture=neutral, PublicKeyToken=null'. Le fichier spécifié est introuvable.'
So it's a duplicate issue.
Provide some way to bind outside of xaml, something like EventBinding.Bind
There could be an issue with Avalonia
There could be an issue when we change a VM to another one
I'm running into an issue when binding to the same event of different controls. I am binding to the Initialized event of multiple controls. When I do so, I get a System.MissingMethodException 'Constructor on type' with a long hex code.
<Image Initialized="{e:EventBinding Test}" ... />
<Button Initialized="{e:EventBindingn Test}" .../>
This error is repeated with any Event type that I've tried. (Initialize, AttachedToVisualTree, PointerPressed)
If the controls are all of the same type or if I bind to a different event for each different control, I do not have this issue. It only occurs when binding to the same event of different control types.
Hi, it would be nice if you could add support for v11-preview in a preview nuget package, it would only require a version change of Avalonia to a v11-preview. It does need a new build because there is a binary breaking change from pre v11 to v11.
I recently upgraded my project from Avalonia version 0.10.13 to version 11.1.1. With this change any AXAML page that uses event binder throws the following error where it is trying to reference Avalonia.Visuals v 0.9.0.0.
Severity Code Description Project File Line Suppression State Details
Error One or more errors occurred. (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 45, position 5.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 45, position 52.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 45, position 90.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 64, position 5.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 64, position 52.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 64, position 90.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 94, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 94, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 94, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 119, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 119, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 119, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 159, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 159, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 159, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 171, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 171, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 171, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 183, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 183, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 183, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 195, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 195, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 195, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 207, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 207, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 207, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 219, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 219, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 219, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 233, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 233, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 233, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 246, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 246, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 246, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 259, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 259, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 259, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 271, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 271, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 271, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 284, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 284, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 284, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 294, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 294, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 294, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 304, position 6.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 304, position 53.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 304, position 91.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 318, position 4.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 318, position 51.) (Internal compiler error: Could not load file or assembly 'Avalonia.Visuals, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. (AvaloniaXamlIlOptionMarkupExtensionTransformer) Line 318, position 89.) ProjectName C:\PATH_TO_AXAMLS\FILENAME.axaml
In the solution explorer the package throws no errors or warnings.
Has anyone seen this issue before or have ideas on what I can check?
Actions Completed:
dotnet restore
on the solutionAdd support for paths like this "NestedObj.NestedObj.MyMethod"
Hi @Serg046, thanks for a great tool! I run into an Exception when trying to bind to the KeyDown event (and many other events) in my .NET 5 wpf app. See image for the location in the code where it fails in EventBinding.cs (I changed the code slightly for simpler display of nullvalue) :
The event TextChanged or MouseLeftButtonDown works fine. Here's my xaml:
Any idea on how to fix, or if I'm doing something wrong?
Would be a nice feature for consistency with the command pattern.
The following code crashes because value types should be boxed before passing:
var button = XamlReader.Parse<Button>($"<Button Height=\"{expected}\" Name=\"Btn\" Click=\"{{e:EventBinding Invoke, {{Binding ElementName=Btn, Path=Height}}}}\"/>");
button.DataContext = new Action<object>(n => num = (double)n);
Constructions like this should be supported
{EventBinding Method, {Binding SomeProp}}
Rewrite the following method so that it will be generic without boxings
internal static object ResolveBinding(Binding binding, FrameworkElement source, int position)
{
if (!BindingOperations.IsDataBound(source, _properties[position]))
{
BindingOperations.SetBinding(source, _properties[position], binding);
}
return source.GetValue(_properties[position]);
}
Like this demo : https://github.com/j4587698/EventBindingTest
When I tap the border, the event will be printed tapped
twice.
public void M() {
int a = 6;
Test(a, "");
}
public void Test(double x, string y) {}
The construction above compiles to this
IL_0000: ldc.i4.6
IL_0001: stloc.0
IL_0002: ldarg.0
IL_0003: ldloc.0
IL_0004: conv.r8
IL_0005: ldstr ""
IL_000a: call instance void C::Test(float64, string)
Add support for such conversions
Such stuff should be available https://bartwullems.blogspot.com/2017/07/wpf-debounce-trick.html
Now the cache is based on type, method and arguments. It seems that caching based on type only is more efficient. Investigate this option (method and arguments can be passed at runtime).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.