views:

372

answers:

1

I have developed several custom controls in a wpf application that use triggers. what is the fastest way to convert the code so that I have a single code base that works both in the wpf application and the silverlight applicaiton. Here is a sample of the code:

 <Style x:Key="sButtonAction" TargetType="Button">
  <!--<Setter Property="BitmapEffect" Value="{StaticResource BannerEffect}" />-->
  <Setter Property="Height" Value="25" />
  <Setter Property="Margin" Value="4" />
  <Setter Property="Cursor" Value="Hand" />
  <Setter Property="Template">
   <Setter.Value>
    <ControlTemplate TargetType="Button">
     <Border x:Name="PART_Border" CornerRadius="10"
       BorderThickness="{StaticResource sBorderThicknessStandard}"
       BorderBrush="{StaticResource bColorBorder}"
       Background="{StaticResource ButtonActionBackground}">
      <TextBlock x:Name="PART_TextBlock" Margin="5,2,5,2" HorizontalAlignment="Center"
        VerticalAlignment="Center" Foreground="White">
        <ContentPresenter HorizontalAlignment="Center"
         VerticalAlignment="Center" /></TextBlock>
     </Border>
     <ControlTemplate.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
       <Setter TargetName="PART_TextBlock" Property="Foreground"
         Value="#990000"></Setter>
      </Trigger>
      <Trigger Property="IsPressed" Value="True">
       <Setter TargetName="PART_Border" Property="Background"
         Value="{StaticResource ButtonActionBackgroundSelected}"></Setter>
      </Trigger>
     </ControlTemplate.Triggers>
    </ControlTemplate>
   </Setter.Value>
  </Setter>
 </Style>
+2  A: 

As painful as it sounds, changing your triggers to use the VisualStateManager is your best bet. It is included in WPF 4.0, and if you are stuck on an earlier version, you can grab it off of codeplex.

It sucks that Silverlight doesn't support triggers, but if you need to support both platforms, I think that is your best bet.

Abe Heidebrecht