I have a combobox which is bound to a property called "BlockDetails" in the viewmodel. When I expand the combobox I can see the items inside it. But the problem is it doesn't select/display the item. On top when I set SelectedValue="{Binding BlockName,Mode=TwoWay}"
, in the output window it gives a binding path error saying 'Error: BindingExpression path error: 'BlockName' property not found on 'Presentation.InstrumentUI.ViewsLoggedIn.ServiceUtilityMethodsView'. BindingExpression: Path='BlockName' DataItem='Presentation.InstrumentUI.ViewsLoggedIn.ServiceUtilityMethodsView'; target element is 'Windows.UI.Xaml.Controls.ComboBox' (Name='null'); target property is 'SelectedValue' (type 'Object')'.
I don't understand why is it going and searcing in the View instead of the model. Please help.
Here is my combobox
<ComboBox uwpControls:DockPanel.Dock="Right"
Margin="16,0,0,0"
Style="{StaticResource ComboBoxStyleForm}"
ItemsSource="{x:Bind ViewModel.BlockDetails,Mode=TwoWay}"
DisplayMemberPath="BlockName"
SelectedValuePath="BlockName"
SelectedValue="{Binding BlockName,Mode=TwoWay}"></ComboBox>
In the code behind I have the ViewModel as follows, the item source for the Combobox is bound correctly
public IServiceUtilityMethodsViewModel ViewModel { get; }
public ServiceUtilityMethodsView()
{
InitializeComponent();
ViewModel = LifetimeScope.Resolve<IServiceUtilityMethodsViewModel>();
DataContext = this;
}
Here is the viewmodel property.
public List<VmServiceMethodBlockDefinition> BlockDetails
{
get => _blockDetails;
set => Set(ref _blockDetails, value);
}
In my model the class is declared as follows,
public class VmServiceMethodBlockDefinition : BindableBaseThreadSafe
{
private string _blockName;
public string BlockName
{
get => _blockName;
set => Set(ref _blockName, value);
}
private List<VmServiceMethodBlockParameters> _blockParameters;
public List<VmServiceMethodBlockParameters> BlockParameters
{
get => _blockParameters;
set => Set(ref _blockParameters, value);
}
}