wpf在样式中查找内部网格
我有一个在 xaml 中定义的按钮样式,里面有一个故事板和一个网格。故事板将网格的不透明度设置为 0.1。问题是如何通过代码恢复它。我想我可以访问网格并将不透明度设置为 1,但我找不到通过 C# 获取网格的方法。
这是代码:
xaml:
<Style x:Key="BevelWLButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}" x:Name="bbtemplate">
<ControlTemplate.Resources>
<Storyboard x:Key="FadeOut" >
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.05"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid x:Name="grid">
-------------- up is the grid i find
</Style>
按钮是由代码创建的,并且样式
在此处正确设置,我开始故事板:
var story = btn.Template.Resources["FadeOut"] as Storyboard;
if (story != null)
{
story = story.Clone();
story.Begin(btn,btn.Template);
}
但是当我尝试时,
currentButton.Resources["grid"]; or currentButton.Template.Resources["grid"];
结果为空。所以,我无法重新建立不透明度
有什么想法吗?
提前致谢。
I have a button style defined in xaml, inside i have an storyboard and among other things a grid. The storyboard set the opacity of the grid to 0.1. The question is how to restore it via code. I think i can access the grid and set the opacity to 1 but i can not find a way to get the grid via c#.
Here is the code:
xaml:
<Style x:Key="BevelWLButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}" x:Name="bbtemplate">
<ControlTemplate.Resources>
<Storyboard x:Key="FadeOut" >
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.05"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid x:Name="grid">
-------------- up is the grid i find
</Style>
the buttons are created by code and the style is setted properly
here i begin the storyboard:
var story = btn.Template.Resources["FadeOut"] as Storyboard;
if (story != null)
{
story = story.Clone();
story.Begin(btn,btn.Template);
}
but when i try to
currentButton.Resources["grid"]; or currentButton.Template.Resources["grid"];
the result is null. So, i can not restablish opacity
Any Idea?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做
You can do this
您是否尝试过
currentButton.Template.FindName("grid", currentButton) as Grid
Did you try
currentButton.Template.FindName("grid", currentButton) as Grid