First off, thankyou for the solution to my previous question here
That solution works very well, however, i'm struggling to bind the change of one of the properties. I have the BackgroundColour binding well when the UI loads with the following code: UI View
<StackLayout x:Name="stlShippingOrders" Spacing="5" Padding="0,0,0,5" >
<CollectionView Margin="0,-6,0,0" IsGrouped="True" ItemsSource="{Binding
ShippingItems}">
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<StackLayout Padding="5,-5,5,-5" Orientation="Horizontal"
BackgroundColor="LightBlue" HeightRequest="45">
<Label Text="{Binding Shipment.OrderCode}"
VerticalOptions="Center"/>
<Label Text="{Binding Shipment.CustomerName}"
VerticalOptions="Center"/>
<Label Text="{Binding Shipment.DeliveryDate}"
HorizontalOptions="EndAndExpand" VerticalOptions="Center" />
</StackLayout>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Padding="5,2,5,2" Text="{Binding ItemDescription}"
BackgroundColor="{Binding BackgroundColour}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
ShippingItem Model (with added BacgroundColour property)
public class ShippingItem
{
public String ShippingItemId { get; set; }
public string ShippingItemScanCode { get; set; }
public string ItemDescription { get; set; }
public string ShippingOrderId { get; set; }
public bool IsLoaded { get; set; }
// Default set to transparent #00FFFFFF
public string BackgroundColour { get; set; } = "#00FFFFFF";
}
Class for grouping
public class ShippingItemGroup : ObservableCollection<ShippingItem>
{
public ShippingOrder Shipment { get; private set; }
public ShippingItemGroup(ShippingOrder shipment, ObservableCollection<ShippingItem>
shippingItems) : base(shippingItems)
{
Shipment = shipment;
}
}
ViewModel code that creates the group list and binds correctly
public ObservableCollection<ShippingItemGroup> ShippingItems {
get; private set; } = new ObservableCollection<ShippingItemGroup>();
foreach (var item in thisShipment.ShippingOrders)
{
ShippingItems.Add(new ShippingItemGroup(item,
item.ShippingItems));
}
ViewModel code that updates the list object when it is loaded. This is the bit i'm having trouble with, the shippingItem.BackgroundColour = "FFA533" changes the collection but doesn't update the UI.
foreach (ShippingItemGroup shippingItemGroup in ShippingItems)
{
foreach(ShippingItem shippingItem in
shippingItemGroup.Shipment.ShippingItems)
{
if(shippingItem.ShippingItemScanCode == scanCode)
{
shippingItem.IsLoaded = true;
shippingItem.BackgroundColour = "FFA533";
IsShipmentHeaderVisible = true;
IsShippingOrdersVisible = true;
IsErrorMessageVisible = false;
ScanCode = "";
}
}
}
