AvaloniaUI / avalonia-docs

https://docs.avaloniaui.net/docs/welcome
65 stars 213 forks source link

Add global resource lookup from code section #239

Closed robloo closed 11 months ago

robloo commented 1 year ago

@timunie I update the section you were working on to include a bit more info for those coming from other XAML UI frameworks. Accessing resources from code is a little tricky in Avalonia (and honestly it needs to be better). Discussion was here:

robloo commented 11 months ago

@maxkatz6 @timunie Should I close this?

timunie commented 11 months ago

@robloo I have mixed feelings here and let the team decide. Thx for remembering me anyways

maxkatz6 commented 11 months ago

(Try)FindResource works with both Control.Resources and Control.Styles here. I still don't understand where is the issue.

av.zip

It works specifically due to: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Application.cs#L212-L217 https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/Styling/Styles.cs#L118-L135 https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/StyledElement.cs#L453-L458

I assume original confusion goes from the App.Resources["Name"] usage, which will ignore styles. Which is exactly the confusing in https://github.com/AvaloniaUI/Avalonia/issues/6021. But as I said, there is no need to yet another "find resource" method.

robloo commented 11 months ago

@maxkatz6 I wouldn't say there is a confusion here at this point. It simply does not work on my end in a real app and the helper method discussed is required. I checked it again to confirm and this isn't just me either: others using FluentAvalonia are seeing it too. That likely means there is a bug some place. It's not worth our time to discuss this further for documentation so I'll close this. The work-around will remain in my code.

Separately, it would be good to align the indexer lookup implementation to match WPF.