Question about DataBinding
Posted: 18 Oct 2013, 05:17
Having some issues with databinding, am I missing something obvious?
My listview declaration:
I've set the name to ItemsListView, for retrieval via code. The ItemSource is bound to Items.
I've also gotten the name of the listview, and tried setting ItemsSource...I got a blank entry in the listview, but nothing else.
Is there something I'm just missing?
Thanks,
JC
My listview declaration:
Code: Select all
<ListView
Name="ItemsListView"
Grid.ColumnSpan="2"
Grid.Row="1"
ItemsSource="{Binding Items}">
<ListView.View>
<GridView>
<GridViewColumn Header="Item">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Foreground="White" Text="{Binding Name}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Code: Select all
// Use this for initialization
private void Start()
{
_uiPanel = GetComponent<NoesisGUIPanel>();
_Root = _uiPanel.GetRoot<FrameworkElement>();
_DrawingCanvas = _Root.FindName<Canvas>("MainWindow");
// Tried putting this at the end of Start(), didn't make a difference.
_DrawingCanvas.SetDataContext(_InventoryData);
_InventoryData = new MyInventoryData { Items = new Collection() }; // Set data context for entire panel to this.
MyInventoryItemData item = new MyInventoryItemData { Name = "Wooden Sword", Quality = 75.3f, Weight = 12.5f }; // Add an item to the inventory
_InventoryData.Items.Add(item);
}
}
[Extended]
public class MyInventoryData : BaseComponent
{
public Collection Items;
public string Title;
}
[Extended]
public class MyInventoryItemData : BaseComponent
{
public string Name;
public float Quality;
public float Weight;
}
Is there something I'm just missing?
Thanks,
JC