This project is read-only.

Creating a New Document with Multiple Controls (and Binding)

Oct 7, 2011 at 3:17 PM
Edited Oct 7, 2011 at 3:21 PM

I am having some trouble understanding how to populate content into a programmatically generated document. I have a XAML template that I want to associate with the document, then I want to bind an object to it. The XAML template has references to properties of the object. I can successfully create the document, but unless I set content manually (meaning I create labels and such in the code-behind then set the content to that), I cannot get any content to show up.

My goal: create new document in the code behind, assign the template, then bind the object that is a variable in that code behind.

Is this possible?

 

The application is setup with a listbox on the left side and the document panel on the right. I double click on a list box item, get the object from that listboxitem in the MouseDoubleClick method, then create a new document (open the item clicked on like a file opening), and bind the derived object to the document for all of it's data. The content/layout of the document should be defined with a XAML template where controls in that template are referencing properties of the bound object for their content.

Here is what I have tried without any luck:

 

        private void PersonList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (sender is ListBoxItem)
            {
                ListBoxItem lbi = (ListBoxItem)sender;
                if (lbi == null || !lbi.IsSelected) return;
                Person person = (Person)PersonList_lb.SelectedItem;
                if (person == null) return;

                //We now have our bound pickup object in the driver var
                outputMessage("Double clicked person " + person.PersonID);

                Window win = Application.Current.MainWindow;
                DataTemplate dt = Application.Current.MainWindow.FindResource("PersonDocumentTemplate") as DataTemplate;
                //Open a person details document
                /*
                var documentContent = new DocumentContent();
                documentContent.Title = driver.ReversedName + " (" + person.PersonID + ")";
                documentContent.DataContext = person;
                //documentContent.SetBinding
                Window win = Application.Current.MainWindow;
                DataTemplate dt = win.FindResource("PersonDocumentTemplate") as DataTemplate;
                //documentContent.ContentTemplate = new DataTemplate("PersonDocumentTemplate");
                //documentContent.ContentTemplate = (DataTemplate)FindResource("PersonDocumentTemplate");
                //documentContent.ContentTemplate = (DataTemplate)Resources["PersonDocumentTemplate"];
                documentContent.ContentTemplate = dt;
                documentContent.ApplyTemplate();
                //documentContent.Content = person;
                if (!documentContent.HasContent)
                    outputMessage("There is no content to apply to the new person document!");
                //Label l = new Label();
                //l.Content = "Hello, content!";
                //documentContent.Content = l;
                documentContent.Show(dockManager);
                documentContent.Activate();
                */

                var documentContent = new DocumentContent();
                documentContent.DataContext = person;
                Label l = new Label();
                l.SetBinding(DependencyProperty.Equals, 
                documentContent.Content = l;
                documentContent.Show(dockManager);
                documentContent.Activate();
            }
        }

 

 

 

Oct 15, 2011 at 5:41 AM

bump... anyone?

Dec 22, 2011 at 6:59 AM

Hi robnewton,

Did you fix it? Got same issue.

If you solve can you post your solution.

 

thanks,

thenndral.

Dec 22, 2011 at 5:27 PM
I did not. Moved on to another project and it has been shelved since

Thanks,
Rob

Sent from my iPhone

On Dec 22, 2011, at 1:59 AM, "thenndral" <notifications@codeplex.com> wrote:

From: thenndral

Hi robnewton,

Did you fix it? Got same issue.

If you solve can you post your solution.

thanks,

thenndral.

For 80 Years — Delivering Solutions that Exceed Expectations.


This communication and any transmitted documents are intended to be confidential. If there is a problem with this transmission, please contact the sender. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.

Dec 23, 2011 at 8:18 AM

Hi RobNewton,

Thanks for  your reply.

Anyone??

 

Thanks,

thenndral