I am unable to use a converter in XAML. I followed the documentation however it seems incorrect or outdated.
namespace Mazes.Ui.Temporary.Converters
{
public class TimeSpanConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
// ...
}
}
}
I register the converter in MainWindow where the window is declared.
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Mazes.Ui.Temporary.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:Mazes.Ui.Temporary.Views"
xmlns:local="clr-namespace:Mazes.Ui.Temporary.Converters;assembly=Mazes.Ui.Temporary"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Mazes.Ui.Temporary.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="Mazes.Ui.Temporary">
<Window.Resources>
<local:TimeSpanConverter x:Key="timeSpanConverter" />
</Window.Resources>
<views:MainView />
</Window>
I then try to use it in MainView where it is bound to a property in the view model.
<TextBlock Text="{CompiledBinding ComputeTime, Converter={StaticResource timeSpanConverter}}" Grid.Row="0" Grid.Column="1"/>
However I get the following error in both MainView and MainWindow: Static resource 'timespanConverter' not found.