Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xaml empty string comparison not working anymore #35

Closed
Yelo420 opened this issue Jan 18, 2025 · 1 comment · Fixed by #36
Closed

Xaml empty string comparison not working anymore #35

Yelo420 opened this issue Jan 18, 2025 · 1 comment · Fixed by #36
Labels
bug Something isn't working

Comments

@Yelo420
Copy link

Yelo420 commented Jan 18, 2025

Since the last update to 11.2.0.7 the following is not working anymore.
Code is not part of a template binding or something and worked exactly like this in a earlier version.

VIEW MODEL:

private string mystring= "";
internal string MyString
{
    get { return mystring; }
    set
    {
        SetProperty(ref mystring, value);
    }
}

XAML:

<Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="Black" CornerRadius="5">
	<i:Interaction.Behaviors>
		<ia:DataTriggerBehavior Binding="{Binding MyString}" ComparisonCondition="Equal" Value="">
			<ia:ChangePropertyAction PropertyName="IsVisible" Value="False" />
		</ia:DataTriggerBehavior>
		<ia:DataTriggerBehavior Binding="{Binding MyString}" ComparisonCondition="NotEqual" Value="">
			<ia:ChangePropertyAction PropertyName="IsVisible" Value="True" />
		</ia:DataTriggerBehavior>
	</i:Interaction.Behaviors>
	<StackPanel>
		<TextBlock FontSize="25" Foreground="White">
			<i:Interaction.Behaviors>
				<ia:DataTriggerBehavior Binding="{Binding MyString}" ComparisonCondition="NotEqual" Value="">
					<ia:ChangePropertyAction PropertyName="Text" Value="{Binding MyString}" />
				</ia:DataTriggerBehavior>
			</i:Interaction.Behaviors>
		</TextBlock>	
	</StackPanel>
</Border>
@wieslawsoltes wieslawsoltes added the bug Something isn't working label Jan 20, 2025
@wieslawsoltes
Copy link
Owner

wieslawsoltes commented Jan 20, 2025

It seems like ChangePropertyAction.Value binding is updated with delay, it uses prior value for binding while DataTriggerBehavior.Binding uses newer value. Seems like when using StyledElement as base class for actions e.g. ChangePropertyAction is causes this issue, if I revert to Action that inherits from AvaloniaObject it works. Looks like some kind of Avalonia bug ?

So the issue is that avalonia property changed event has different order when you change base class from AvaloniaObject to StyledElement.

https://github.com/wieslawsoltes/Avalonia.Xaml.Behaviors/tree/Repro35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants