将 wpf 触发器转换为 silverlight 的最佳方法?

发布于 2024-08-29 16:29:31 字数 1641 浏览 1 评论 0原文

我在 wpf 应用程序中开发了几个使用触发器的自定义控件。转换代码的最快方法是什么,以便我拥有可在 wpf 应用程序和 silverlight 应用程序中工作的单一代码库。这是代码示例:

 <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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他夏了夏天 2024-09-05 16:29:31

尽管听起来很痛苦,但更改触发器以使用 VisualStateManager 是最好的选择。它包含在 WPF 4.0 中,如果您坚持使用早期版本,可以从 Codeplex 获取它。

Silverlight 不支持触​​发器很糟糕,但如果您需要支持这两个平台,我认为这是您最好的选择。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文