locked
Template Selector (Benjamin) - 5/5/2006 5:10 AM PST RRS feed

  • Question

  • By: Benjamin

    Hi everybody!
    
    I would like to have a simple sample of the use of a TemplateSelector :
    
    For instance I've got 2 Templates "Template1" and "Template2" for a button.
    
    I would like to change the current template when I press the button.
    Something like that in my code behind::
    
    DataTemplateSelector tmpSelect=new DataTemplateSelector();
    tmpSelect.SelectTemplate(this.Button , this.Button.Template)  
    =Application.Current.MainWindow.FindResource("Template1");
    
    I know the code is wrong but I wasn't able to fix it... If any one gots a 
    clue.....
    
    Thanks!
    -- 
    Benjamin
    Monday, February 18, 2008 11:56 PM

Answers

  • By: Lengesh Palniappan (MS)
    Hi,
    Let us assume you have both the templates defined inside the main scene
    itself. Let us assume you call your button as 'Button'. Have the button
    selected in sparkle. Now in the event palette add the event click and
    specify an event handler say ClickHandler. Now sparkle automatically
    switches to code editor. The follwoing code worked for me

    private void ClickHandler(object sender, System.Windows.RoutedEventArgs e)
    {
    this.Button.Template =
    (ControlTemplate)this.FindResource("ButtonBaseControlTemplate2");
    }

    If you have further questions feel free to post back in the forum.
    regards,
    Lingesh
    "Benjamin" <Benjamin@discussions.microsoft.com> wrote in message
    news:2536A2F2-C9F3-4DC7-84F4-55CA529C2564@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 4:32 PM

All replies

  • By: Lengesh Palniappan (MS)
    Hi,
    Let us assume you have both the templates defined inside the main scene
    itself. Let us assume you call your button as 'Button'. Have the button
    selected in sparkle. Now in the event palette add the event click and
    specify an event handler say ClickHandler. Now sparkle automatically
    switches to code editor. The follwoing code worked for me

    private void ClickHandler(object sender, System.Windows.RoutedEventArgs e)
    {
    this.Button.Template =
    (ControlTemplate)this.FindResource("ButtonBaseControlTemplate2");
    }

    If you have further questions feel free to post back in the forum.
    regards,
    Lingesh
    "Benjamin" <Benjamin@discussions.microsoft.com> wrote in message
    news:2536A2F2-C9F3-4DC7-84F4-55CA529C2564@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 4:32 PM
  • By: Benjamin
    Thanks! Easiest solutions are always the more difficult to find ... ;-)

    --
    Benjamin


    "Lingesh Palaniappan (MS)" wrote:

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 4:33 PM