Replies: 3 comments 6 replies
-
@JohnHDev, thanks for the write up! I'm afraid passing the getter as a parameter is not supported now, the tooling expects an inline lambda expression. If you look at the code generation, you’ll see that it uses interceptors to write code for self.SetBinding(Label.TextProperty, ...) at compile time. This process relies on the lambda’s source code to generate the correct binding code. By requiring that the lambda expression be inline, the generator can always retrieve and analyze the Roslyn expression tree. In order to support passing the getter as a parameter, we’d need to figure out how to capture the lambda’s expression tree when it’s defined elsewhere. |
Beta Was this translation helpful? Give feedback.
-
You can modify the public static Label TextBinding<TSource, TProperty>(this Label self, Expression<Func<TSource, TProperty>> getter)
{
self.SetBinding(Label.TextProperty, getter);
return self;
} and it should work ... I think |
Beta Was this translation helpful? Give feedback.
-
Am I missing something here? BindingBase.Create<TSource, TProperty> already supports static lambda expression getter function, for example: label.SetBinding(Label.TextProperty, BindingBase.Create<ViewModel, DateTime>(static m => m.Date, source: viewModel)); |
Beta Was this translation helpful? Give feedback.
-
Hi, I am investigating the use of compiled bindings in a small fluent framework Ive created. Given the following code that uses a compiled binding:
I want to pass a static function to my own fluent function like this:
The code for the TextBinding method looks like this:
But I get the following error:
The error is quite clear, so was thinking I might need to look at the codegen to see how that is implemented. Before I do that I wanted to check if Ive missed anything.
It might be Ive just had too much turkey at this point to see the wood for the trees. 🌲
(I have simplified the code above massively to get to a small example of what Im trying to achieve)
Beta Was this translation helpful? Give feedback.
All reactions