WPF 模板中的控件修改
来源:互联网 发布:办公软件excel心得体会 编辑:程序博客网 时间:2024/05/17 12:03
模板:
<ControlTemplate x:Key="HomeBtnNewTemplate" TargetType="{x:Type Button}">
<Grid Width="{TemplateBinding Width}" Background="{TemplateBinding Background}"
Height="{TemplateBinding Height}" ClipToBounds="True">
<Rectangle x:Name="glassCube" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Opacity="1"
Fill="{StaticResource ShopBtnNewBrush}" RenderTransformOrigin="0.5,0.5"
RadiusX="10" RadiusY="10">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform />
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Rectangle.Opacity" Value="1" TargetName="glassCube" />
</Trigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property="Rectangle.Opacity" Value="1" TargetName="glassCube" />
</Trigger>
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard Name="mouseEnterBeginStoryboard">
<Storyboard AutoReverse="True">
<DoubleAnimation Storyboard.TargetName="glassCube"
Storyboard.TargetProperty=
"(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
By="0.03" Duration="0:0:0.2" />
<DoubleAnimation
Storyboard.TargetName="glassCube"
Storyboard.TargetProperty=
"(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
By="0.03" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave">
<EventTrigger.Actions>
</EventTrigger.Actions>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
修改方法:
ControlTemplate template = (ControlTemplate)this.TryFindResource("HomeBtnTemplate");
Rectangle rec = template.FindName("glassCube", btnTest) as Rectangle;
Console.WriteLine(rec.Name);
同理可以拿到模板中的其他对象进行相应更改
- WPF 模板中的控件修改
- WPF中的ControlTemplate(控件模板)
- WPF中的ControlTemplate(控件模板)
- WPF中的控件模板(ControlTemplate)
- WPF中的控件模板(ControlTemplate)
- WPF中的ControlTemplate(控件模板)
- WPF中的ControlTemplate(控件模板)
- WPF中的ControlTemplate(控件模板)
- WPF中的ControlTemplate(控件模板)
- wpf datagrid 得到模板中的控件
- WPF控件模板与样式最方便的修改方法
- WPF默认控件模板
- WPF:控件模板
- WPF中的控件模板(ControlTemplate)——出自《IT168》
- WPF中的控件模板(ControlTemplate)——出自《IT168》
- wpf 修改控件Background
- WPF中的模板
- WPF中的菜单模板
- 使用软引用缓存Bitmap
- 值得学习的Android开源项目
- 触摸屏原理
- 使用CopyOnWriteArrayList来解决ArrayList上的ConcurrentModificationException
- OPENCV之形态学处理
- WPF 模板中的控件修改
- Linux下,不能以根用户身份运行google chrome 浏览器的解决办法
- 《设计模式解析》 第7章 Adapter模式 复习题
- 经典SQL语句大全
- What's values in SuppressWarning
- 定制导航栏的返回按钮
- usb鼠标枚举过程深度解析(上)
- 没有找到MSVCR90D.DLL的两种解决方法
- ubuntu 10.10 安装selinux