?
Solved

WPF -  Template.FindName  - Can't Find

Posted on 2011-03-22
3
Medium Priority
?
2,971 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
politex earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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:…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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