0

I have a bound ComboBox where I need to show default item "No Selection". ComboBox should close with no text selection and no selected item, When the user selects this option ("No Selection") from list.

These are the data resources

<UserControl.Resources>
    <my:iTimeKeepBaseDataSet x:Key="iTimeKeepBaseDataSet" />
    <CollectionViewSource x:Key="codeSetsViewSource" Source="{Binding Path=codeSets, Source={StaticResource iTimeKeepBaseDataSet}}" />
    <CollectionViewSource x:Key="allMattersViewSource" Source="{Binding Path=allMatters, Source={StaticResource iTimeKeepBaseDataSet}}" />
    <my:CodeIdToDetailsConverter x:Key="codeIdDetailsConverter" />

</UserControl.Resources>

This is ComboBox data template

                  <DataTemplate x:Key="CodeSetDataCellEditTemplate">
                        <ComboBox DataContext="{StaticResource codeSetsViewSource}"
                                  ItemsSource="{Binding}"
                                  SelectedValuePath="{Binding Path=codeSetId}"
                                  SelectionChanged="OnCodeSetsSelectionChanged"
                                  Style="{StaticResource ComboboxTemplate}">

                            <ComboBox.ItemTemplate>
                                <DataTemplate>

                                    <TextBlock>
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="{}{0} - {1}">
                                                <Binding Path="codeSetId" />
                                                <Binding Path="codeSetName" />
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                    </DataTemplate>

Template column of DataGrid

<DataGridTemplateColumn x:Name="codeSetId1Column"
                                        Width="SizeToHeader"
                                        CellEditingTemplate="{StaticResource CodeSetDataCellEditTemplate}"
                                        Header="Code Set ID 1"
                                        my:DataGridAttachedProperty.ColumnName="codeSetId1">

Please suggest me a solution for this.

Thanks in advance

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Ravi Shankar
  • 153
  • 1
  • 5

1 Answers1

0

You can use CompositeCollection

    <CompositeCollection>
       <ComboBoxItem IsEnabled="False" Foreground="Black">Select Item</ComboBoxItem>
       <CollectionContainer Collection="{Binding Source={StaticResource DataKey}}" />    
    </CompositeCollection>

But, you can't use Binding here, workaround is to use BindingProxy with CompositeCollection

See my answer here and comments for more details

Community
  • 1
  • 1
Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184