Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

display a user control inside another user control RSS

9 replies

Last post Jun 04, 2009 07:19 AM by yosirosner

(0)
  • yosirosner

    yosirosner

    Member

    1 Points

    7 Posts

    display a user control inside another user control

    May 25, 2009 01:51 PM | LINK

    Hi, i found in the internet a user control that i want to display inside my user control. this is the user control that i found: (file name is "CaptchaControl.xaml")
  • Raju Hosamani

    Raju Hosamani

    Member

    300 Points

    54 Posts

    Re: display a user control inside another user control

    May 25, 2009 03:12 PM | LINK

    hi Yosi,

    Add NamespaceName into page2.xaml as shown below

    xmlns:fromInternet="clr-namespace:NamespaceName;assembly=assemblyName" 

    in Usercontrol Tag

    Decalre CaptchaControl control in Page2.xaml as shown below

    <fromInternet:CaptchaControl x:Name="CaptchaControl"/>

    All .cs code also work here, access code using  name (CaptchaControl) of the control.


    Please mark it as answered, if this helps to meet your requirement
    Thanks,
    Raju

     

  • yosirosner

    yosirosner

    Member

    1 Points

    7 Posts

    Re: display a user control inside another user control

    May 26, 2009 06:17 AM | LINK

    Hi Raju and thak you for your time! i steel have those problems / questions: 1.in my first post i tried to cut & paste my code, so i will be more understandable, but the post came out without any code. how it can be done? is it possible to keep also the colors of the editor? that way things will be more cleare. 2.i feel confused, but maybe i didn't explain myself well: the CaptchaControl code was found in the internet, i mean of course that i didn't wrote the code, but now it's a normal file in my proj. i guess that i need also to declare name for the CaptchaControl.xaml, something like "x:Name="CaptchaControl"", isn't it? 3. does "frominternet" must be called like that? 4. what should i write instead of "NamespaceName" and "assemblyName"? Thanks again, Yosi
  • Raju Hosamani

    Raju Hosamani

    Member

    300 Points

    54 Posts

    Re: display a user control inside another user control

    May 28, 2009 06:39 AM | LINK

    Hi Yosi, 

    1. You can cut/copy the code. colors of the editor will remain same.

    2. .xaml name is declared as x:Class and not x:Name

    3. You can use any friendly name, I used "frominternet". 

    4. NamespaceName- Name of Solution, assemblyName- name of the assembly. If you still confused just right click on Solution and Click on Property item, you will get AssemlyName and NamespaceName.

    Another simple way to achieve your requirement is

    create object of CaptchaControl and set desired Grid column and row value to that object 

    CaptchaControl
    captchaControl= new CaptchaControl();

    captchaControl.SetValue(Grid.ColumnProperty, 0);

    captchaControl.SetValue(Grid.RowProperty, 0);

     Please mark it as answered, if this helps to meet your requirement
    Thanks,
    Raju

     

  • yosirosner

    yosirosner

    Member

    1 Points

    7 Posts

    Re: display a user control inside another user control

    May 31, 2009 10:35 AM | LINK

    Hi Raju, 

    1. here is my Page2.xaml:

    UserControl x:Class="SilverlightTest2.Page2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:fromInternet="clr-namespace:SilverlightTest2;assembly=" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"

    i omit the assembly name because i couldn't find it though i tried right click on Solution and Click on Properties item

    2. after this declaration the intelisens found alone that CaptchaControl is one of the files in the "fromInternet" xmlns, and i added this line to my Page2.xaml:

    but i have get an error:Error 1 Unknown namespace clr-namespace:SilverlightTest2;assembly=. [Line: 102 Position: 66] E:\SilverlightTest2\SilverlightTest2\Page2.xaml  

    and i also get a warning: Warning 2 The tag 'CaptchaControl' does not exist in XML namespace 'clr-namespace:SilverlightTest2;assembly='. E:\SilverlightTest2\SilverlightTest2\Page2.xaml

    thanks a lot

    yosi 

  • Raju Hosamani

    Raju Hosamani

    Member

    300 Points

    54 Posts

    Re: display a user control inside another user control

    Jun 01, 2009 08:03 AM | LINK

    HI Yosi,

    Did you tried this...

    create object of CaptchaControl and set desired Grid column and row value to that object 

    CaptchaControl captchaControl= new CaptchaControl();

    captchaControl.SetValue(Grid.ColumnProperty, 0);

    captchaControl.SetValue(Grid.RowProperty, 0);

    Please mark it as answered, if this helps to meet your requirement
    Thanks,
    Raju

  • yosirosner

    yosirosner

    Member

    1 Points

    7 Posts

    Re: display a user control inside another user control

    Jun 01, 2009 03:36 PM | LINK

    Hi Raju, I tried it but get few other problems... i will be grateful if you can take a look in my last post and try to solve it that way. thanks again, yosi
  • FuryDiamond

    FuryDiamond

    All-Star

    23869 Points

    4072 Posts

    Re: display a user control inside another user control

    Jun 01, 2009 03:50 PM | LINK

    Make sure that the CaptchaControl is in the project and that its namespace is the same as the projects. For the code example below, the namespace is SilverlightApplication14.

    CaptchaControl.xaml

    <UserControl x:Class="SilverlightApplication14.CaptchaControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Grid />
    </UserControl>
     

    CaptchaControl.cs

    using System.Windows.Controls;
    
    namespace SilverlightApplication14
    {
        public partial class CaptchaControl : UserControl
        {
            public CaptchaControl()
            {
                InitializeComponent();
            }
        }
    }

    Page.xaml

    <UserControl x:Class="SilverlightApplication14.Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:fromInternet="clr-namespace:SilverlightApplication14"             
        >
        <Grid>
            <fromInternet:CaptchaControl />
        </Grid>
    </UserControl>
    Please "Mark as Answer" if this post answered your question. :)

    Silverlight 5 3D Tutorials: http://silverlight.bayprince.com
    Blog: http://blog.bayprince.com
    Twitter: http://twitter.com/bayprince
  • Raju Hosamani

    Raju Hosamani

    Member

    300 Points

    54 Posts

    Re: display a user control inside another user control

    Jun 04, 2009 06:53 AM | LINK

    Hi Yosi,

    please go through this link http://silverlight.net/learn/tutorials/usercontrols.aspx .It explanations  step by step to create and use User control.

    Please mark it as answered, if this helps to meet your requirement
    Thanks,
    Raju

     

  • yosirosner

    yosirosner

    Member

    1 Points

    7 Posts

    Re: display a user control inside another user control

    Jun 04, 2009 07:19 AM | LINK

    Thank you all, Raju and Furi, but my boss decided to leave using silverlight, so it is not so important to fix my problem any more... Yosi