WPF 动态添加带样式按钮

2020-12-29 03:27

阅读:755

标签:nts   alt   xmlns   horizon   ref   schema   nes   height   targe   

1.添加字典

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:GenerateLogo"
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">




x:Name="RefractionLayer"
Fill="#A7FF0000"
StrokeThickness="3">

















IsSmoothJoin="True"
Point1="75.860,47.685"
Point2="69.111,45.196"
Point3="50.167,45.196"/>

IsSmoothJoin="True"
Point1="7.469,52.580"
Point2="1.000,53.252"
Point3="1.000,44.999"/>

IsSmoothJoin="True"
Point1="9.106,14.370"
Point2="27.875,0"
Point3="50,0"/>

IsSmoothJoin="True"
Point1="99.139,39.369"
Point2="98.999,40.084"
Point3="98.999,45.499"/>







CenterX="0.5"
CenterY="0.5"
ScaleX="1"
ScaleY="1.997"/>



















CenterX="0.5"
CenterY="0.5"
ScaleX="1.5"
ScaleY="1.5"/>













CenterX="0.5"
CenterY="0.5"
ScaleX="1"
ScaleY="1.997"/>
















CenterX="0.5"
CenterY="0.5"
ScaleX="1.5"
ScaleY="1.5"/>













CenterX="0.5"
CenterY="0.5"
ScaleX="1"
ScaleY="1.997"/>
















2.App.Xmal中添加创建的字典







3.动态添加按钮的方法

private void GetUiElement_F()
{
//Uri resourceUri = new Uri("Images/logo.png", UriKind.Relative);
//StreamResourceInfo streamInfo = Application.GetResourceStream(resourceUri);

//BitmapFrame temp = BitmapFrame.Create(streamInfo.Stream);
//var brush = new ImageBrush();
//brush.ImageSource = temp;
var tb = new Button
{
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
FontSize = 11,
FontWeight = FontWeights.Bold,
Foreground = Brushes.Transparent,
Width = 100,
Height = 100,
Margin = new Thickness(10),
};
// logo.RegisterName("btn1", tb);
tb.SetResourceReference(StyleProperty, "GlassYButton");
// tb.Background = brush;
tb.Click += new RoutedEventHandler(btnEvent_Click);
logo.Children.Add(tb);
}

4.效果图

技术图片技术图片

 

WPF 动态添加带样式按钮

标签:nts   alt   xmlns   horizon   ref   schema   nes   height   targe   

原文地址:https://www.cnblogs.com/gkxg/p/13299540.html


评论


亲,登录后才可以留言!