Avalonia.Xaml.Behaviors
Avalonia.Xaml.Behaviors copied to clipboard
Null value in expression ''." - In EventTriggerBehavior and DataTriggerBehavior
Issue #17 was already about this, but the 'solution' (There wasn't really a solution posted) mentioned there doesn't work for me.
I still get the following warning during execution: [Binding] Error in binding to "Avalonia.Xaml.Interactions.Core.InvokeCommandAction"."Command": "Null value in expression ''." (Avalonia.Xaml.Interactions.Core.InvokeCommandAction #12001237)
The code does work (The double tap event triggers the command successfully), but emits this warning for each of the event triggers during runtime. I have exactly the same problem with a DataTrigger, but that one refuses to work at all.
Take this simple example:
Relevant XAML namespaces, for your convenience
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:ia="clr-namespace:Avalonia.Xaml.Interactions.Core;assembly=Avalonia.Xaml.Interactions"
XAML
<TextBlock Name="driveLabel" Text="{Binding DisplayName}">
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="DoubleTapped" SourceObject="{Binding #driveLabel}">
<ia:InvokeCommandAction CommandParameter="{Binding}" Command="{Binding DataContext.OpenDriveCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
</TextBlock>
C# code
public ReactiveCommand<MyViewModel, Unit> OpenDriveCommand { get; }
public MyConstructor()
{
this.OpenDriveCommand = ReactiveCommand.Create<MyViewModel, Unit>(this.openDrive);
}
private Unit openDrive(MyViewModel viewModel)
{
// Do stuff
return Unit.Default;
}
So setting 'Unit' as the return type of the command, does not get rid of this warning. Does anybody know how to get rid of this warning?
I also would like to ask if if someone knows what would be wrong with my DataTrigger. It emits the same warning as the EventTriggerBehavior, only then with DataTriggerBehavior as type, and it doesn't do anything at all. The image source is supposed to differ per directory entry type, but instead nothing is shown now.
<Image Height="19" Margin="0 0 5 0" Name="image">
<i:Interaction.Behaviors>
<ia:DataTriggerBehavior Binding="{Binding Type}" ComparisonCondition="Equal" Value="{x:Static models:DirectoryEntryType.Directory}">
<ia:ChangePropertyAction TargetObject="{Binding #image}" PropertyName="Source" Value="/Assets/Icons/folder_closed.ico"/>
</ia:DataTriggerBehavior>
<ia:DataTriggerBehavior Binding="{Binding Type}" ComparisonCondition="Equal" Value="{x:Static models:DirectoryEntryType.File}">
<ia:ChangePropertyAction TargetObject="{Binding #image}" PropertyName="Source" Value="/Assets/Icons/cpp.ico"/>
</ia:DataTriggerBehavior>
</i:Interaction.Behaviors>
</Image>
What version are you using?
Oh yeah, sorry! I forgot to add that at the end.
I have the following Avalonia dependencies:
Can you try with 0.10.0-preview6
, the fixes are not on 0.9.x
series.
I've updated everything to 0.10.0-preview6, but the original problem(s) is/are still there.
Did anyone get anywhere with this? I'm using 0.10.0 stable from Nuget, and experiencing the same issue with a DataTriggerBehavior
with an InvokeCommandAction
. Interestingly, for a DataTriggerBehavior
element containing a ChangePropertyAction
, the Action
is invoked successfully, though the Debug output complains - but when the ChangePropertyAction
is replaced with a InvokeCommandAction
or CallMethodAction
, the Command
/method is not invoked.
@calmcl1 I still have the exact same problem (Also on the new package version). No solution, unfortunately...
Still have the exact issue in the latest version....
Still have the exact issue in the latest version....
<b:DataTriggerBehavior Binding="{Binding HeaderLocation}" ComparisonCondition="Equal" Value="{x:Null}">
HeaderLocation is property with nullable enum type
When "HeaderLocation" is not null, it works.
I get the binding error but the command will eventually get bound and the command will be invoked at runtime.
I'm using Avalonia.Xaml.Behaviors 11.0.0-preview4
I'm also getting this "scary" error, yet all the code works just fine. Tried a couple of variations on the binding but no joy in eliminating the error.
Here's the "error":
[Binding] Error in binding to 'Avalonia.Xaml.Interactions.Core.CallMethodAction'.'TargetObject': 'Null value in expression '{empty}' at ''.' (CallMethodAction #64457312)
And here are the two flavors of binding I tried:
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="PointerPressed">
<ia:CallMethodAction TargetObject="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type local:Tests}}}" MethodName="handleTestClick" />
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
and
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="PointerPressed">
<ia:CallMethodAction TargetObject="{Binding DataContext, RelativeSource={RelativeSource AncestorType=UserControl}}" MethodName="handleTestClick" />
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
Only difference is the AncestorType. Both work and produce the same error message as above. Would love to know how to get rid of this error message.
Using Avalonia 0.10.18.
Thanks, Chris
I'm also getting this "scary" error, yet all the code works just fine. Tried a couple of variations on the binding but no joy in eliminating the error.
Here's the "error":
[Binding] Error in binding to 'Avalonia.Xaml.Interactions.Core.CallMethodAction'.'TargetObject': 'Null value in expression '{empty}' at ''.' (CallMethodAction #64457312)
And here are the two flavors of binding I tried:
<i:Interaction.Behaviors> <ia:EventTriggerBehavior EventName="PointerPressed"> <ia:CallMethodAction TargetObject="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type local:Tests}}}" MethodName="handleTestClick" /> </ia:EventTriggerBehavior> </i:Interaction.Behaviors>
and
<i:Interaction.Behaviors> <ia:EventTriggerBehavior EventName="PointerPressed"> <ia:CallMethodAction TargetObject="{Binding DataContext, RelativeSource={RelativeSource AncestorType=UserControl}}" MethodName="handleTestClick" /> </ia:EventTriggerBehavior> </i:Interaction.Behaviors>
Only difference is the AncestorType. Both work and produce the same error message as above.
Would love to know how to get rid of this error message.
Using Avalonia 0.10.18.
Thanks,
Chris
I'm using the latest Avalonia nightly build. And I'm getting tons of this error in the VS window. Any plans to fix this?
any news on that? im facing the same issue with a binding in control template
Any news on that? I'm facin the same issue with a binding in a templated control. The binding in Projektanker.Icons.Avalonia/Icon.axaml is producing the error log
[Binding]Error in binding to 'Projektanker.Icons.Avalonia.IconImage'.'Value': 'Null value in expression '{empty}' at ''.'(IconImage #15537542)
[Binding]Error in binding to 'Projektanker.Icons.Avalonia.IconImage'.'Brush': 'Null value in expression '{empty}' at ''.'(IconImage #15537542)
@wieslawsoltes, any feedback on why closing this as "not planned"?
I am using "Output" window to debug and I am not prepared to go through such useless spam when switching views.
Setting Options\Avalonia XAML Editor\Minimum Log Verbosity
doesn't affect the output. Did someone assigned "Fatal" priority to this output? Can it at least be lowered to "Information"?
I urgently need some kind of workaround please.
Its not issue with this library
@wieslawsoltes If it is not an issue with Avalonia could you please tell me how to prevent the error from happening? That would be great 😊 Thanks in advance.