I'm having a problem setting the Binding/Path property in my XAML.
I know this ComboBox's ItemSource
property is updating properly, since I get a bunch of empty text-boxes when I update the viewmodel
(instead of textboxes with text, which is what I expect).
So I believe the Binding in the DataTemplate
section of my ComboBox needs a different binding path, but I'm not sure what to set the binding path to.
<ComboBox ItemsSource="{Binding Path=Locations}" Visibility="{Binding SettingsOptionsVisibility}" Grid.Column="0" x:Name="locationCB" VerticalAlignment="Top" SelectionChanged="locationCB_SelectionChanged" HorizontalAlignment="Left" Width="350" Height="30" IsHitTestVisible="False" IsEnabled="False" Focusable="False">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Here's a picture of my LocationCB's ItemsSource in the Watch List in my Codebehind: http://imgur.com/x4SYWER
As expected, my combobox is populated with 8 (textless) elements. What do I need to do to get my binding the text to Name to connect up?
EDIT: code for the Locations object in the ViewModel:
public ObservableCollection<Location> Locations { get; set; }
And code for the Location class wrapped in the observable collection, as requested:
public class Location
{
public Guid LocationID;
public Guid ParentID;
public String Name;
public bool isValid;
}
Name
a property defined inLocation
class? Post code for that as well. – Rohit Vats<StackPanel>
element, it should just be a textbox inside of itemtemplate – KcvinIsHitTestVisible
andIsEnabled
set to false. It doesn't seem like you would be able to open the ComboBox. – evanbName
should be a property and not field. Convert field to property and it will work fine. – Rohit Vats