Avalonia.Xaml.Behaviors icon indicating copy to clipboard operation
Avalonia.Xaml.Behaviors copied to clipboard

Null value in expression ''." - In EventTriggerBehavior and DataTriggerBehavior

Open darkcharmander opened this issue 3 years ago • 6 comments

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>

darkcharmander avatar Nov 17 '20 11:11 darkcharmander

What version are you using?

wieslawsoltes avatar Nov 17 '20 11:11 wieslawsoltes

Oh yeah, sorry! I forgot to add that at the end.

I have the following Avalonia dependencies: image

darkcharmander avatar Nov 17 '20 11:11 darkcharmander

Can you try with 0.10.0-preview6, the fixes are not on 0.9.x series.

wieslawsoltes avatar Nov 17 '20 12:11 wieslawsoltes

I've updated everything to 0.10.0-preview6, but the original problem(s) is/are still there. image

darkcharmander avatar Nov 17 '20 12:11 darkcharmander

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 avatar Mar 25 '21 15:03 calmcl1

@calmcl1 I still have the exact same problem (Also on the new package version). No solution, unfortunately...

darkcharmander avatar Apr 05 '21 15:04 darkcharmander

Still have the exact issue in the latest version....

laolarou726 avatar Oct 06 '22 03:10 laolarou726

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.

изображение

slavslavin avatar Oct 20 '22 12:10 slavslavin

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

mgnslndh avatar Nov 15 '22 21:11 mgnslndh

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

clawton avatar Jan 19 '23 19:01 clawton

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?

laolarou726 avatar Jan 20 '23 21:01 laolarou726

any news on that? im facing the same issue with a binding in control template

tisis2 avatar Jun 01 '23 09:06 tisis2

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)

just-seba avatar Feb 18 '24 10:02 just-seba

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

sinatrocious avatar Feb 19 '24 12:02 sinatrocious

Its not issue with this library

wieslawsoltes avatar Feb 19 '24 13:02 wieslawsoltes

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

just-seba avatar Feb 19 '24 13:02 just-seba