I have the following comboBox
<ComboBox x:Name="cmbBuscarPor" HorizontalAlignment="Left" Text="Buscar por " Margin="210,10,0,0" VerticalAlignment="Top" Width="120" Height="30" VerticalContentAlignment="Center">
<ComboBoxItem Content="Nombre" HorizontalContentAlignment="Center"/>
<ComboBoxItem Content="Apellido paterno" HorizontalContentAlignment="Center"/>
<ComboBoxItem Content="Puesto" HorizontalContentAlignment="Center"/>
</ComboBox>
I want to put a text that appears at startup that is not any of the options that are already default
The easiest way is to use
CompositeCollection
to merge text and default data from the database directly into the ComboBox, for example:And in Resources define
StaticResource
to link the options ofComboBox
to yourDataContext
, because the direct link inCollectionContainer
does not work correctly.This way you can define your ComboBox options only in xaml, for example
Another way:
Or like this:
You'll obviously have to add your other options, but this is probably the easiest way to do it.
However, there is a downside to this method, which is when the text inside your ComboBox will not be editable, it is still selectable. However, given the low quality and complexity of every alternative I've found to date, this is probably the best option.