views:

203

answers:

1

I have a listbox that displays Shipment Items (custom class) that are formatted using a datatemplate (see below). There is a border element in the template (I am calling it a Gem) that displays which item is active (not selected) which will be the item to which products will be added.

template.png

There is a boolean property in the shipment class (Active) which is set in a click event handler for the Gem element. Normally the Gem is supposed to be dark as in the first image, then lit when active.

I have a DataTrigger set up in the DataTemplate to handle the change in the color of the Gem.

    <DataTemplate.Triggers>
 <DataTrigger Binding="{Binding Active}" Value="True">
  <Setter TargetName="ActiveGem" Property="Background">
   <Setter.Value>
    <RadialGradientBrush>
     <GradientStop Color="Red" Offset="0"/>
     <GradientStop Color="#FF820000" Offset="1"/>
    </RadialGradientBrush>
   </Setter.Value>
  </Setter>
 </DataTrigger>
 <DataTrigger Binding="{Binding Active}" Value="False">
  <Setter TargetName="ActiveGem" Property="Background">
   <Setter.Value>
    <RadialGradientBrush>
     <GradientStop Color="Red" Offset="0"/>
     <GradientStop Color="#FF820000" Offset="1"/>
    </RadialGradientBrush>
   </Setter.Value>
  </Setter> 
 </DataTrigger>
</DataTemplate.Triggers>

For some reason, however, when the application loads all of the gems are lit showing the packages are all active.

**Due to the reputation limits on stackOverflow I can't post more hyperlinks yet. Image below is at same domain as the one above.

/ExternalImages/ActiveItems.PNG

I have checked that all of the items are in fact Active = False, but the gem is always lit. Additionally, when I run the click event I go through the Package collection and set all Active = False then set the TemplatedParent of the sender to be active.

    Dim ActiveShipments = From ship In ShipmentData _
                         Where ship.Active = True
    For Each MyShipment As Shipment In ActiveShipments
        MyShipment.Active = False
    Next
    Dim Gem As Border = sender
    Dim ShipmentObject As ContentPresenter = Gem.TemplatedParent
    ShipmentObject.Content.Active = True

The Gems do not return to their unlit state (which they never were in the first place). They only remain lit. Any ideas?

Cory

--Oddly, Only showed up in the code box the first edit... Fixed now.

A: 

Actually, I figured it out. When I was making the RadialGradiantBrushes I either did not save the unlit one or I copy/pasted the lit on onto it and did not edit it or something. The datatrigger was firing properly, but since both gradients were of the lit variety, it looked like nothing was happening. Sorry for the trouble!

Cory

OffApps Cory