Set Fill Brush in a Class

I have a Class Card and I want each Card to have a different background color:

<Each Items="{cards}">
  <Card BgColor="{colorvar}" />

Here is my Class:

  <Panel ux:Class="Card" ux:Name="Card" Padding="15">
      <Brush ux:Property="BgColor"/>

      <Rectangle CornerRadius="4" Fill="{Property Card.BgColor}" Layer="Background" />

But all I get is ERROR: Object reference not set to an instance of an object and a blank (no error, just blank) preview that I have to rebuild.

Note that outside of a Class, it works: <Circle Fill="{colorvar}" /> works fine.


Try setting an initial value for the property, e.g.

<Panel ux:Class="Card" ux:Name="Card" Padding="15" BgColor="Black">

Works fine! Thanks