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

Crash with binding path="/" in multibinding #4067

Open
Kermalis opened this issue Jun 1, 2020 · 5 comments
Open

Crash with binding path="/" in multibinding #4067

Kermalis opened this issue Jun 1, 2020 · 5 comments

Comments

@Kermalis
Copy link
Contributor

Kermalis commented Jun 1, 2020

Hello, I am having some issue that seems simple but I really cannot find any way to do it:
I have a list of MyEnum values, I have them in a ComboBox and have been using a converter to convert the MyEnum items to IBitmaps that are drawn for each ComboBox item.
Now I need to have another property of my object used as a parameter of the converter, so I looked to multiconverters, but I cannot find out how to plug in the values to the converter
The old way was:

<DataTemplate x:Key="Menu">
  <Image Source="{Binding Converter={x:Static infrastructure:MyConverter.Instance}, ConverterParameter=ExampleParam, Mode=OneWay}"/>
</DataTemplate>
.....
<ComboBox Items="{Binding MyObj.SelectableItems}" ItemTemplate="{StaticResource Menu}" SelectedItem="{Binding MyObj.MyEnumValue}"/>

From browsing Google, I came up with this:

<DataTemplate x:Key="Menu">
  <Image Stretch="None">
    <Image.Source>
      <MultiBinding Converter="{x:Static infrastructure:MyMultiConverter.Instance}" ConverterParameter="ExampleParam" Mode="OneWay">
        <Binding Path="SelectedItem" ElementName="MyOtherComboBox"/>
        <Binding Path="/"/> <!--This crashes-->
      </MultiBinding>
    </Image.Source>
  </Image>
</DataTemplate>

The Path="/" is apparently supposed to reference the current item in the iteration, like the regular bindings do, but it crashes instead. The crash is here: https://pastebin.com/raw/N29dzRaQ

Also, the converter is never called when I have Path="/", even when the items populate the ComboBox

I'm on 0.9.10

@Kermalis
Copy link
Contributor Author

I can't test right now, but any chance this is fixed by #6246 ?

@Gillibald
Copy link
Contributor

Gillibald commented Jul 14, 2021

CurrentItem is used in the context of https://docs.microsoft.com/en-us/dotnet/api/system.windows.data.collectionview.currentitem?view=net-5.0 and that isn't available under Avalonia

Path="/" is a shortcut for CurrentItem

@maxkatz6
Copy link
Member

TIL there is '/' in bindings.

@Kermalis
Copy link
Contributor Author

Does any workaround exist? I couldn't find one so I left it as it was a year ago

@maxkatz6
Copy link
Member

@Kermalis something like {Binding $parent[ComboBoxItem].DataContext} might help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants