0

In, WPF, XAML, I have a Style that's being applied to the items of a ComboBox, I want to get the current item's Content Property but this doesn't seem to work:

<dxe:ComboBoxEdit.Items>
    <Style TargetType="{x:Type dxe:ComboBoxEditItem}">
        <Style.Setters>
            <Setter Property="Content" Value="{Binding Converter={StaticResource CrsNameCvtor}, ConverterParameter={Binding Content,RelativeSource={RelativeSource Self}}}"/>
        </Style.Setters>
    </Style>
</dxe:ComboBoxEdit.Items>
MindSwipe
  • 7,193
  • 24
  • 47
Dan
  • 274
  • 6
  • 14
  • What is `dxe:ComboBoxEdit` ? Do you miss a library tag? – Sinatr Aug 14 '19 at 11:41
  • It's Devexpress's ComboBox, please think of it as WPF's default ComboBox. – Dan Aug 14 '19 at 11:42
  • 1
    And why is the Style defined inside the `Items` tag? That makes no sense. – Clemens Aug 14 '19 at 11:42
  • I think you're right on that one! Should put in the Combobox directly I guess. – Dan Aug 14 '19 at 11:43
  • No, it belongs into `ItemContainerStyle`. – Clemens Aug 14 '19 at 11:43
  • 1
    And you can't bind a Binding's ConverterParameter. See here: https://stackoverflow.com/q/15309008/1136211 – Clemens Aug 14 '19 at 11:47
  • No, that's ok. What I'm trying to do is, I have the content in a format like: "abcd||stuf|stuff", and I'm trying to show it as only "abcd" while keeping the string intact in the VM – Dan Aug 14 '19 at 11:47
  • 1
    So the converter should just manipulate the Binding's source value? You don't need a ConverterParameter. Just take the `value` argument of the Convert method. – Clemens Aug 14 '19 at 11:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/197925/discussion-between-dan-and-clemens). – Dan Aug 14 '19 at 11:54

1 Answers1

2

The Style should be assigned to the ComboBox's ItemContainerStyle property, and you don't need to set the Binding's ConverterParameter at all:

<dxe:ComboBoxEdit.ItemContainerStyle>
    <Style TargetType="dxe:ComboBoxEditItem">
        <Setter Property="Content"
                Value="{Binding Converter={StaticResource CrsNameCvtor}}"/>
    </Style>
</dxe:ComboBoxEdit.ItemContainerStyle>
Clemens
  • 123,504
  • 12
  • 155
  • 268