Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - A question about new an object.

 
 
Old 07-24-2006   #1 (permalink)
wisenighthsu@ulead.com.tw


 
 

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 SpecsSystem Spec
Old 08-17-2006   #2 (permalink)
Nick Kramer [MSFT]


 
 

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 SpecsSystem Spec
 

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46