【问题标题】:How to Change the Name of style in xaml when Button is pressed in WPF在WPF中按下按钮时如何更改xaml中的样式名称
【发布时间】:2014-12-17 12:48:09
【问题描述】:

我有两个样式名称,例如 MyStyleButton 和 MyStyleClick,如果按下按钮,那么我想应用 MyStyleClick 样式,否则在 Xaml 中应用另一个 MyStyleButton。

<Button Name="btnExportPDF" Content="PDF" Click="btnExportPDF_Click" Height="40" Width="100" Style="{StaticResource MyStyleButton}" Margin="5" />

【问题讨论】:

  • 想知道使用控件模板设置 ToggleButton 的样式是否是您真正想要的。

标签: c# .net wpf


【解决方案1】:

https://stackoverflow.com/a/18201435/880709

private void AnotherWay_Click(object sender, RoutedEventArgs e)
{
    label1.Style = (Style)Application.Current.Resources["AnotherWayStyle"];
} 

【讨论】:

【解决方案2】:

一个例子是 jQuery,但它有不止一种方法来做到这一点

jQuery.(".theClass").attr("class","Name of new class");

【讨论】:

  • 我想要在 Xaml WPF 而不是 Jquery 中
  • @Bhavanaky 看看 Anatoly Ruchka 的答案,这也是他链接的一种方式
  • @Bhavanaky 这也是一种方式stackoverflow.com/questions/1783005/…
  • 嗨 Hugo,我想在 Xaml 页面中添加,但不在 .cs 文件中,有什么办法可以这样做
  • @Bhavanaky 你不必在cs文件中做这个你可以简单地在你的xaml页面中做这个:)
猜你喜欢
  • 1970-01-01
  • 2010-12-04
  • 2014-07-15
  • 2015-02-04
  • 2021-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多