服装网站建设规划书需求分析,wordpress 视频站模板下载失败,网站双链接怎么做,重庆做网站哪家好有时候需要动态的设置一些按钮的状态模板。使一个button显示不同的内容#xff0c;比如Button未点击安装显示#xff1a; 安装后显示#xff1a; 可以通过设置button的content#xff0c;通过content来设置不同的模板来实现功能#xff0c;以下是代码#xff1a;
MainWi…有时候需要动态的设置一些按钮的状态模板。使一个button显示不同的内容比如Button未点击安装显示 安装后显示 可以通过设置button的content通过content来设置不同的模板来实现功能以下是代码
MainWindow.xaml
Windowx:ClassWPF_ButtonTemplate.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:localclr-namespace:WPF_ButtonTemplatexmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006TitleMainWindowWidth800Height450mc:IgnorabledWindow.ResourcesBitmapImage x:KeySetting_Extension UriSourcepack://application:,,,/Installed.png /ControlTemplate x:KeyUnInstallTemplate TargetTypeButtonBorderx:Nameborder1Width100Height30BackgroundLightGrayBorderBrushDarkGrayBorderThickness1.5CornerRadius8TextBlockx:NamecontentTBHorizontalAlignmentCenterVerticalAlignmentCenterText{TemplateBinding Content} //Border/ControlTemplateControlTemplate x:KeyInstalledTemplate TargetTypeButtonBorder x:Nameborder1 BackgroundLightYellow CornerRadius8StackPanel Margin13,7,13,7 OrientationHorizontalImageWidth16Height16HorizontalAlignmentLeftVerticalAlignmentCenterSource{DynamicResource Setting_Extension} /TextBlockx:NamecontentTBMargin4,0,0,0HorizontalAlignmentCenterVerticalAlignmentCenterFontSize{TemplateBinding FontSize}Foreground{TemplateBinding Foreground}Text{TemplateBinding Content} //StackPanel/Border/ControlTemplateStyle x:KeyNomalBtn TargetTypeButtonSetter PropertyWidth Value100 /Setter PropertyHeight Value30 /Style.TriggersTrigger PropertyContent Value未安装Setter PropertyTemplate Value{StaticResource UnInstallTemplate} //TriggerTrigger PropertyContent Value已安装Setter PropertyTemplate Value{StaticResource InstalledTemplate} //Trigger/Style.Triggers/Style/Window.ResourcesGridButtonx:NamebtnClickButton_ClickContent未安装Style{StaticResource NomalBtn} //Grid
/WindowMainWindow.cs
using System.Windows;namespace WPF_ButtonTemplate
{/// summary/// Interaction logic for MainWindow.xaml/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void Button_Click(object sender, RoutedEventArgs e){if (string.Equals(btn.Content, 未安装))btn.Content 已安装;elsebtn.Content 未安装;}}
}
项目免费下载地址
【免费】WPF-ButtonTemplate资源-CSDN文库