I am trying to bind a listview element to a member of a structure, but I cannot get it to work.
The structure is pretty simple:
public struct DeviceTypeInfo
{
public String deviceName;
public int deviceReferenceID;
};
in my view model I keep a list of these structures and I want the "deviceName" to appear in the list.
public class DevicesListViewModel
{
public DevicesListViewModel( )
{
}
public void setListOfAvailableDevices(List<DeviceTypeInfo> devicesList)
{
m_availableDevices = devicesList;
}
public List<DeviceTypeInfo> Devices
{
get { return m_availableDevices; }
}
private List<DeviceTypeInfo> m_availableDevices;
}
I tried the following, but I can not get the binding to work, do I need to use a native source?
<ListBox Name="DevicesListView" Grid.Column="0" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="10" MinHeight="250" MinWidth="150" ItemsSource="{Binding Devices}" Width="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding DeviceTypeInfo.deviceName}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
source
share