添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

ComboBox.SelectedItem only returns the typename and not the selected Value When using a Datatemplate #3199

Closed
@ajmcateer

Description

I have a combobox configured like so

      <ComboBox SelectedItem="{Binding SelectedModule, Mode=OneWayToSource}" Grid.Column="0" BorderBrush="Black" Grid.Row="2" Height="25" Margin="5" Items="{Binding SubCommands}">
        <ComboBox.ItemTemplate>
          <DataTemplate>
            <TextBlock Text="{Binding DisplayName}" ToolTip.Tip="{Binding Description}"/>
          </DataTemplate>
        </ComboBox.ItemTemplate>
      </ComboBox>

And the viewmodel is

        public string SelectedModule
            get => selectedModule;
            private set
                var res = value;
                this.RaiseAndSetIfChanged(ref selectedModule, value);

I am getting back the typename of the Items property instead of the value of the textblock text. How can I get that WPF mentions DisplayMemberName but that doesn't seem to exist in Avalonia.

I also tried
SelectionBoxItem="{Binding SelectedModule, Mode=OneWayToSource}"
but that didn't work either