Can anybody please help me. I’ve created a custom combobox which has an itemtemplate,i’m binding the selected item but i cant see it as a selected item in the combo box.
Here is the code:
the xaml:
<Grid>
<hcw:ClassificationSelectorThreeLayerComboBox Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="4" SelectedItem="{Binding Path=SelectedValue,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding CarePlanCatalogs.AllLinkedClassifications}" Margin="3,3,20,3"/>
</Grid>
the viewmodel:
class NeedViewModel : CarePlanEntityViewModelBase
{
public LinkedClassification SelectedValue
{
get { return selectedValue; }
set
{
if (value != null)
{
selectedValue = value;
OnPropertyChanged("SelectedValue");
}
}
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="ClassificationSelectorThreeLayerDataTemplate">
<Border BorderBrush="#ACACAC" BorderThickness="0,0,0,1">
<StackPanel>
<Label Content="{Binding Path=ClassificationComponent.ComponentName}" Margin="0,0,0,4" />
<Label Content="{Binding Path=MainClass.MainClassName}" Margin="0,0,0,4" />
<Label Content="{Binding Path=SubClass.SubClassName}" Margin="0,0,0,4" />
</StackPanel>
</Border>
</DataTemplate>
Does it work with regular combobox?
Do you set SelectedValue to one of instances of LinkedClassification from CarePlanCatalogs.AllLinkedClassifications or create another instance? If you create another instance, you should override Equals and GetHashCode on LinkedClassification, so wpf could find your LinkedClassification in CarePlanCatalogs.AllLinkedClassifications