Solved

WPF -  Template.FindName  - Can't Find

Posted on 2011-03-22
3
2,696 Views
Last Modified: 2013-11-12
I have the following template

     <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type FlowDocumentReader}">
                 
 <Button x:Name="btnPrint" Height="25" Width="70" ToolTip="Print"  Margin="5,0,0,0" >
                 
But when I run my code to find the buttonl... it's always returns null ..

  Button btnPrint  = (Button)this.flowdocReader.Template.FindName("btnPrint",this.flowdocReader);
0
Comment
Question by:JElster
3 Comments
 
LVL 3

Accepted Solution

by:
politex earned 500 total points
ID: 35196148
Hi, you are sure what a FlowDocumentReader is loaded? sample:
public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            var a = fdr.Template.FindName("bbb", this.fdr);
            //a =null
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var a = fdr.Template.FindName("bbb", this.fdr);
            //a = bbb
        }

        private void fdr_Loaded(object sender, RoutedEventArgs e)
        {
            var a = fdr.Template.FindName("bbb", this.fdr);
            //a = bbb
        }
}

Open in new window

0
 
LVL 11

Expert Comment

by:saragani
ID: 35196175
Ok, lets start with the basic question... why are you trying to access your button in Code-Behind instead of using Binding, Commands, MVVM and god knows what.

Where must be a better what to do what you are doing (which I don't know what exactly).
0
 
LVL 1

Author Comment

by:JElster
ID: 35197668
I had my code in  OnApplyTemplate()
Which previous articles mentioned... but it does Not Find it.
It DOES in the Window_Loaded()
thanks..


I've been trying to every option to wire up a style/template button to a page.
I'm new to all this...
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question