![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | A question about new an object. Dear all: I wrote an Contorl(called:MyControl) and wrote its controltemplate. The control has a membe variable MyButton which is point to an button in the controltemplate. So I wrote the code in the OnApplyTemplate of MyContorl like this.. public override void OnApplyTemplate() { base.OnApplyTemplate(); MyButton = Template.FindName("Button1", this) as Button; } Button1 is the name of a button in the controltemplate. But when I use code to new a MyControl, the OnApplyTemplate doesn't run it. So the MyButton is null. What can I do to new a control and get the button of the controltempate? Thanks a lot. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: A question about new an object. Did you ever get this working? My first thought is that OnApplyTemplate hasn't been called because the template has been applied yet -- the template isn't applied until the layout system puts that element on the screen as part of the layout pass. So if the element isn't in the tree yet, or is not in a visible part of the tree, the template may not have been applied yet. -- -Nick Kramer [MSFT] http://blogs.msdn.com/nickkramer This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm <wisenighthsu@ulead.com.tw> wrote in message news:1153794400.210102.41580@m79g2000cwm.googlegroups.com... > Dear all: > > I wrote an Contorl(called:MyControl) and wrote its controltemplate. > The control has a membe variable MyButton which is point to an button > in the controltemplate. So I wrote the code in the OnApplyTemplate of > MyContorl like this.. > public override void OnApplyTemplate() > { > base.OnApplyTemplate(); > MyButton = Template.FindName("Button1", this) as Button; > } > Button1 is the name of a button in the controltemplate. > > But when I use code to new a MyControl, the OnApplyTemplate doesn't > run it. So the MyButton is null. > > What can I do to new a control and get the button of the > controltempate? > > Thanks a lot. > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Question on 'if object exists' query with if-then | PowerShell | |||
| Object modeling question | .NET General | |||
| foreach-object question | PowerShell | |||
| New-Object question | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||