BarComboBox with ItemTemplate seems to only affect the ItemsSource and not the SelectedItem.

Bars for WPF Forum

Posted 2 months ago by Matt
Version: 24.1.1
Platform: .NET 6.0
Environment: Windows 10 (64-bit)
Avatar

Hi,

I have encountered an issue with BarComboBox control where the ItemTemplate only seem to affect the ItemsSource and not the SelectedItem. This behavior is inconsistent with the default ComboBox and the Ribbon.ComboBox.

Here is a highly simplified example that demonstrates how to replicate the default behavior and the issue.

<!--WORKING-->
<ribbon:ComboBox
        ItemsSource="{Binding MyListOfString, UpdateSourceTrigger=PropertyChanged}"
        SelectedItem="{Binding MySelectedString, 
                       Mode=TwoWay, 
                       UpdateSourceTrigger=PropertyChanged}">

        <ribbon:ComboBox.ItemTemplate>
          <DataTemplate>
              <TextBlock Text="Test" />
          </DataTemplate>
        </ribbon:ComboBox.ItemTemplate>
</ribbon:ComboBox>

<!--WORKING-->
<ComboBox 
         ItemsSource="{Binding MyListOfString, UpdateSourceTrigger=PropertyChanged}"
         SelectedItem="{Binding MySelectedString, 
                        Mode=TwoWay, 
                        UpdateSourceTrigger=PropertyChanged}">

         <ComboBox.ItemTemplate>
               <DataTemplate>
                   <TextBlock Text="Test" />
               </DataTemplate>
          </ComboBox.ItemTemplate>
</ComboBox>

Both of these examples demonstrate the desired behavior, setting both the SelectedItem and the ItemsSource of the ComboBox dropdown to ‘Test’.

Now here's an example in which the ItemTemplate doesn't apply (Essentially the same code):

<bars:BarComboBox
      ItemsSource="{Binding MyListOfString, UpdateSourceTrigger=PropertyChanged}"
      SelectedItem="{Binding MySelectedString, 
                     Mode=TwoWay, 
                     UpdateSourceTrigger=PropertyChanged}">

      <bars:BarComboBox.ItemTemplate>
         <DataTemplate
             <TextBlock Text="Test" />
         </DataTemplate>
      </bars:BarComboBox.ItemTemplate>
</bars:BarComboBox>

The DataTemplate does not seem to impact MySelectedString as anticipated.

Is this by design, or is there a potential workaround for this situation?

Thank you,
Matt

[Modified 2 months ago]

Comments (2)

The latest build of this product (v24.1.2) was released 2 months ago, which was before the next post in this thread.
Answer - Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Matt,

This is actually by design.  BarComboBox isn't the same as a normal WPF ComboBox in its design, even though they share a similar name.  The items for a BarComboBox are presented in an implicit BarMenuGallery on the popup, and that is what the ItemsTemplate is applied to.  Those item templates could have any size or kind of content, while the BarComboBox itself needs to be kept at a consistent "small" size.  We currently show the BarComboBox.Text value in a TextBlock when the BarComboBox is not editable.

It might be possible to make some other DataTemplate specifically for the non-editable BarComboBox's "selection box" item content.

Can you give some additional detail about your scenario?

[Modified 2 months ago]


Actipro Software Support

Posted 2 months ago by Matt
Avatar

Hi,

I attempted to apply a converter to all the displayed values for a particular purpose. However, following your advice, I utilized the .Text property and it functioned perfectly.

Thank you,

Matt.

Add Comment

Please log in to a validated account to post comments.