首页 新闻 会员 周边 捐助

如何取得模板内控件

0
悬赏园豆:20 [已关闭问题]

一个Button应用了某个模板Template="{StaticResource MyButton}",模板内的控件怎么能取得比如

<ControlTemplate x:Key="MyButton" TargetType="Button">
<Grid>
<Rectangle x:Name="Background" RadiusX="0" RadiusY="0" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Cursor="Hand">
<Rectangle.Fill>
<SolidColorBrush Color="{StaticResource RESADisabledColor}"/>
</Rectangle.Fill>
</Rectangle>
<Path HorizontalAlignment="Stretch" Margin="5.5,3.5,5.5,3.5" VerticalAlignment="Stretch" Stretch="Fill" StrokeThickness="1.5" Data="M6.2249999,5.4210529 L6.2249999,12.578949 L11.921428,8.9605255 z" x:Name="IconPlay">
<Path.Fill>
<SolidColorBrush Color="{StaticResource RESAAccentColor}"/>
</Path.Fill>
</Path>
<Rectangle x:Name="MouseOverVisual" RadiusX="0" RadiusY="0" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Opacity="0">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{StaticResource RESAGlareColor}"/>
<GradientStop Color="{StaticResource RESAAccentColor}" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Path HorizontalAlignment="Stretch" Margin="5.5,3.5,5.5,3.5" VerticalAlignment="Stretch" Stretch="Fill" StrokeThickness="1.5" Data="M6.2249999,5.4210529 L6.2249999,12.578949 L11.921428,8.9605255 z" x:Name="IconPlayWhite" Fill="#FFFFFFFF" Opacity="0"/>
<Rectangle x:Name="DisabledVisual" RadiusX="0" RadiusY="0" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Opacity="0">
<Rectangle.Fill>
<SolidColorBrush Color="{StaticResource RESADisabledColor}"/>
</Rectangle.Fill>
</Rectangle>
<Slider x:Name="MySlider"/>
</Grid>
</ControlTemplate>

如何才能取得MySlider控件呢?

江枫渔火的主页 江枫渔火 | 初学一级 | 园豆:140
提问于:2008-11-21 10:26
< >
分享
其他回答(2)
0

xuexi le

Jared.Nie | 园豆:1940 (小虾三级) | 2008-11-21 12:17
0

其实很好找的...

比如:模板中有个Textbox1(updatecommand事件),那就

Textbox tb= e.Item.FindControl("TextBox1") as TextBox;

like%'远远'% | 园豆:635 (小虾三级) | 2008-11-21 18:37
0

根据您的例子有下面的分类

两种情况:

1、前台javascript

var s = document.getElementsByName('<%= MyButton.FindControl("YourServerControlID") %>');

2、后台CS代码

YourServerControlType s = (YourServerControlType)MyButton.FindControl("YourServerControlID")

解释:

YourServerControlID:是您想获得并定义的服务控件ID

YourServerControlType:是您想获得服务器控件类型是什么,如:TextBox或是LinkButton等等。

刚刚 | 园豆:3151 (老鸟四级) | 2008-11-27 15:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册