In an Avalonia window there is a ListBox with an ItemTemplate. In this ItemTemplate the value of the item should be converted, using a ConverterParameter
.
So far so good. But the value for the parameter is dynamic and should be taken either from a TextBox
, or from the view model.
Try #1 – take converter parameter value from view model property:
<ListBox ItemsSource="{Binding SomeElements}" Width="600">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource MagicConverter},
ConverterParameter={Binding RelativeSource={RelativeSource AncestorType=views:MainWindow},
Path=ViewModel.PropertyInViewModel}}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Try #2 – take converter parameter value directly from TextBox:
<ListBox ItemsSource="{Binding SomeElements}" Width="600">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding
Converter={StaticResource MagicConverter},
ConverterParameter={Binding ElementName=DynamicInputTextBox, Path=Text}}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This both works, but the converter gets an Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension object as parameter.
Any ideas on how to solve this?