question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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>

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12

github_iconTop GitHub Comments

4reactions
darkcharmandercommented, Apr 5, 2021

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

0reactions
tisis2commented, Jun 1, 2023

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Null value in expression ''." - In EventTriggerBehavior and ...
It emits the same warning as the EventTriggerBehavior, only then with DataTriggerBehavior as type, and it doesn't do anything at all. The image ......
Read more >
DataTriggerBehavior is not working for null values
I am trying to set visibility of my stackpanel to collapsed if value is null, but DataTriggerBehavior is not changing it's visibility value, ......
Read more >
System.NullReferenceException in Datagrid.Items (export ...
It means the code tries to access members of a type but the type was never created. It's null. Or really, referencing the...
Read more >
What are Fallback and Target Null Values in WPF?
TargetNullValue is used when we want to display the alternate value when the object property is null. If the object value is null...
Read more >
Windows 8 XAML Tips - Creating Blend Behaviors
There are 3 build-in Behaviors: DataTriggerBehavior, EventTriggerBehavior and IncrementalUpdateBehavior. You can create your own Actions and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found