Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:07:06+00:00 2026-06-10T17:07:06+00:00

I’m trying to make a control for a silverlight application and I’m having some

  • 0

I’m trying to make a control for a silverlight application and I’m having some trouble. The control is a treeview. When I select an item it should pass width and height values which update the size of a canvas. They will be templates basically. Let’s say I wanted my templates to be “Big Square” which would pass width and height values of 600 and 600, “Small Square” which would be 400*400, and rectangle which would pass 600 for width and 400 for height. And so on. This would be bound to my canvas width and height properties. The squares would be under a parent called “Squares” and the rectangles under “Rectangles” etc.

I can write a treeview in XAML but can’t attach height and width values to it so can’t bind my canvas height and width to anything. I was thinking of maybe defining my items (with parent, template name, height and width) in a .cs file and using that to populate the treeview. Then when an item is selected the values associated with that item are passed as my width and height to controls in my MainPage.xaml which are already bound to my canvas width and height.

Not much existing code to be added but even if I could get this example working it would be a big help.

<sdk:TreeView x:Name="trvTemplate">
        <sdk:TreeViewItem Header="Squares">
              <sdk:TreeViewItem Header="Big Square"/>
              <sdk:TreeViewItem Header="Smaller Square"/>
        </sdk:TreeViewItem>
        <sdk:TreeViewItem Header="Rectangles">
              <sdk:TreeViewItem Header="Big Rectangle"/>
              <sdk:TreeViewItem Header="Small Rectangle"/>
        </sdk:TreeViewItem>
<\sdk:TreeView>

Is this possible with a treeview and how would I go about it if so? Thanks for any help.

Edit:Thinking about it now I could easily use eventhandlers on each template but I’d rather not do that and go with an mvvm approach.

Something like this maybe?

public class CanvasTemplate
{
    private static List<CanvasTemplate> listTemplates = null;

    public CanvasTemplate(string name, double width, double height)
    {


        new CanvasTemplate("Template 1", 800, 400);
        new CanvasTemplate("Template 2", 600, 600);

        Name = name;
        Width = width;
        Height = height;

    }


    public string Name { get; set; }
    public double Width { get; set; }
    public double Height { get; set; }


}           
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:07:08+00:00Added an answer on June 10, 2026 at 5:07 pm

    This is your xaml

                <sdk:TreeView.ItemTemplate>
                <DataTemplate>
                    <sdk:TreeViewItem Header="{Binding HeaderName}" ItemsSource="{Binding ListTemplates}">
                        <sdk:TreeViewItem.ItemTemplate>
                            <DataTemplate>
                                <sdk:TreeViewItem Header="{Binding Name}"  GotFocus="TreeViewItem_GotFocus"/>
                            </DataTemplate>
                        </sdk:TreeViewItem.ItemTemplate>
    
    
                    </sdk:TreeViewItem>
                </DataTemplate>
            </sdk:TreeView.ItemTemplate>
            </sdk:TreeView>
    

    The Class are

    public class ParentCanvasTemplate
        {
            public ParentCanvasTemplate(string headername)
            {
                if (headername == "Squares")
                {
                    HeaderName = headername;
                    ListTemplates = new List<CanvasTemplate>();
                    CanvasTemplate ct = new CanvasTemplate("Smaller Square", 400, 400);
                    ListTemplates.Add(ct);
                    ct = new CanvasTemplate("Bigger Square", 800, 800);
                    ListTemplates.Add(ct);
                }
                else if (headername == "Rectangles")
                {
                    HeaderName = headername;
                    ListTemplates = new List<CanvasTemplate>();
                    CanvasTemplate ct = new CanvasTemplate("Smaller Rectangle", 600, 400);
                    ListTemplates.Add(ct);
                    ct = new CanvasTemplate("Bigger Rectangle", 800, 600);
                    ListTemplates.Add(ct);
                }
            }
            public string HeaderName { get; set; }
            public List<CanvasTemplate> ListTemplates { get; set; }
        }
    
        public class CanvasTemplate
        {
    
    
            public CanvasTemplate(string name, double width, double height)
            {       
    
                Name = name;
                Width = width;
                Height = height;
    
            }
    
    
            public string Name { get; set; }
            public double Width { get; set; }
            public double Height { get; set; }
    
    
        }  
    

    Add this where ever you have to create your tree view

    List<ParentCanvasTemplate> lst = new List<ParentCanvasTemplate>();
                ParentCanvasTemplate pct = new ParentCanvasTemplate("Squares");
                lst.Add(pct);
                pct = new ParentCanvasTemplate("Rectangles");
                lst.Add(pct);
                trvTemplate.ItemsSource = lst;
    

    This will give you what you want

     private void TreeViewItem_GotFocus(object sender, RoutedEventArgs e)
            {
                string test = ((sender as TreeViewItem).DataContext as CanvasTemplate).Name;
                string Width = ((sender as TreeViewItem).DataContext as CanvasTemplate).Width+"";
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to select an H1 element which is the second-child in its group
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.