WPF 动态添加控件,并实现透明渐进效果

WPF 动态添加控件,并实现透明渐进效果,第1张

Storyboard s = new Storyboard()

this.Resources.Add(Guid.NewGuid().ToString(), s)

DoubleAnimation da = new DoubleAnimation()

Storyboard.SetTarget(da, 你的Image)

Storyboard.SetTargetProperty(da, new PropertyPath("Opacity", new object[]{}))

da.From = 0

da.To = 1

s.Duration = new Duration(TimeSpan.FromSecond(1))

s.Children.Add(da)

s.Begin()

手敲的没验证呢 如果有问题不好意思啦

这是因为标签没有内容。

在下面这两行中间,

Label button1 = new Label()

abc.Children.Add(button1)

添加:

button1.Content="这是个标签按钮"

==================

Label button1 = new Label()

button1.Content="这是个标签按钮"

abc.Children.Add(button1)

结果如下:

一般不这么直接将图片放到canvas中,可以

<Grid>

<Image name="imageContainer"></Image>

<Canvas Name="Image"></Canvas>

</Grid>

CS代码

image 是图片的二进制数组,

或者将图片文件读取到stream中都可以。

MemoryStream stream = new MemoryStream(image)

BitmapImage bitmapImage = new BitmapImage()

bitmapImage.BeginInit()

bitmapImage.StreamSource = stream

bitmapImage.EndInit()

imageShow.Source = bitmapImage


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11377435.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存