×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    19

    Question Cant Make instances with usercontrol

    In Windows Phone7 I created an UserControl in which I am parsing some Data. Now I am not able to make instances of that Usercontrol.If I drag n drop the usercontrol the error occurs.

    When I remove parsing from the Usercontrol I am able to make instances unless I am getting error such as

    Code:
    `"Cannot create instance of '<usercontrolname>' 
    "XapCannotFindFileInPackage]
    Arguments:HelpScreenData.xml 
    Debugging Resource String are unavailable.Often the key and
    arguments provide sufficient information to diagonise the problem.see
    http://go.microsoft.com'/fwlink/?linkid=106663&version5.0.10411.00&
    file=system.xml.dll&key=Xml_cannot find file in Xappackage"

    And my UserControl is

    Code:
    public partial class ques : UserControl
    {
        Popup popup = new Popup();
        tutorial tut = new tutorial();   //another usercontrol
    
        String[] str;
        String[] nam;
        public ques()
        {
            InitializeComponent();
    
       }
     private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
    
            LayoutRoot.Visibility = Visibility.Visible;
    
            buy_bac.Visibility = Visibility.Collapsed;
            buy_hme.Visibility = Visibility.Collapsed;
            buy_qestim.Visibility = Visibility.Collapsed;
            buy_piti.Visibility = Visibility.Collapsed;
            buy_qual.Visibility = Visibility.Collapsed;
            buy_rent.Visibility = Visibility.Collapsed;
            buy_rep.Visibility = Visibility.Collapsed;
            buy_mre.Visibility = Visibility.Collapsed;
    
            if (Modules.Programname == "Buyers")
            {
                buy_bac.Visibility = Visibility.Visible;
                buy_hme.Visibility = Visibility.Visible;
                buy_qestim.Visibility = Visibility.Visible;
                buy_piti.Visibility = Visibility.Visible;
                buy_qual.Visibility = Visibility.Visible;
                buy_rent.Visibility = Visibility.Visible;
                buy_rep.Visibility = Visibility.Visible;
                buy_mre.Visibility = Visibility.Visible;
            }
            XDocument doc = XDocument.Load("HelpScreenData.xml");
            string val = doc.ToString();
    
            XElement doc1 = doc.Descendants("buyer").First();
    
            var parsedPlist = doc1.Descendants("row");
    
            int i = 0;
            str = new string[parsedPlist.Count()];
            nam = new string[parsedPlist.Count()];
            foreach (XElement elem in parsedPlist)
            {
                nam[i] = (string)elem.Element("btn_name");
                str[i] = (string)elem.Element("string");
                i++;
            }
        }
        private void i1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
    
    
            if (nam[0] == buy_bac.Name)
            {
    
    
                Modules.msg = str[0];
                if (Modules.msg != null)
                {
                    if (popup.IsOpen != true)
                    {
    
                        popup.Child = tut;
                        popup.IsOpen = true;
                        popup.VerticalOffset = 200;
                        popup.HorizontalOffset = 50;
                        popup.IsOpen = true;
                        tut.lb_tut.Text = Modules.msg;
                    }
                    else
                    {
                        popup.IsOpen = false;
                    }
                }
                else if (nam[1] == buy_hme.Name)
                {
                    Modules.msg = str[1];
                    if (Modules.msg != null)
                    {
                        if (popup.IsOpen != true)
                        {
                            popup.Child = tut;
                            popup.IsOpen = true;
                            popup.VerticalOffset = 400;
                            popup.HorizontalOffset = 50;
                            popup.IsOpen = true;
                            tut.lb_tut.Text = Modules.msg;
                        }
                        else
                        {
                            popup.IsOpen = false;
                        }
                    }
    
                }
                else if (nam[1] == buy_qestim.Name)
                {
                    Modules.msg = str[2];
                    if (Modules.msg != null)
                    {
                        if (popup.IsOpen != true)
                        {
                            popup.Child = tut;
                            popup.IsOpen = true;
                            popup.VerticalOffset = 400;
                            popup.HorizontalOffset = 50;
                            popup.IsOpen = true;
                            tut.lb_tut.Text = Modules.msg;
                        }
                        else
                        {
                            popup.IsOpen = false;
                        }
                    }
    
                }
            }
    
    
        }
    
        private void i3_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (nam[2] == buy_piti.Name)
            {
                Modules.msg = str[3];
                if (Modules.msg != null)
                {
                    if (popup.IsOpen != true)
                    {
                        popup.Child = tut;
                        popup.IsOpen = true;
                        popup.VerticalOffset = 600;
                        popup.HorizontalOffset = 50;
                        popup.IsOpen = true;
                        tut.lb_tut.Text = Modules.msg;
                    }
                    else
                    {
                        popup.IsOpen = false;
                    }
                }
    
            }
            else if (nam[2] == buy_rent.Name)
            {
                Modules.msg = str[4];
                if (Modules.msg != null)
                {
                    if (popup.IsOpen != true)
                    {
                        popup.Child = tut;
                        popup.IsOpen = true;
                        popup.VerticalOffset = 600;
                        popup.HorizontalOffset = 50;
                        popup.IsOpen = true;
                        tut.lb_tut.Text = Modules.msg;
                    }
                    else
                    {
                        popup.IsOpen = false;
                    }
                }
    
            }
            else if (nam[2] == buy_qual.Name)
            {
                Modules.msg = str[5];
                if (Modules.msg != null)
                {
                    if (popup.IsOpen != true)
                    {
                        popup.Child = tut;
                        popup.IsOpen = true;
                        popup.VerticalOffset = 600;
                        popup.HorizontalOffset = 50;
                        popup.IsOpen = true;
                        tut.lb_tut.Text = Modules.msg;
                    }
                    else
                    {
                        popup.IsOpen = false;
                    }
                }
    
            }
            else if (nam[2] == buy_mre.Name)
            {
                Modules.msg = str[6];
                if (Modules.msg != null)
                {
                    if (popup.IsOpen != true)
                    {
                        popup.Child = tut;
                        popup.IsOpen = true;
                        popup.VerticalOffset = 600;
                        popup.HorizontalOffset = 50;
                        popup.IsOpen = true;
                        tut.lb_tut.Text = Modules.msg;
                    }
                    else
                    {
                        popup.IsOpen = false;
                    }
                }
    
            }
        }

    The XML Parsed is

    <?xml version="1.0" encoding="utf-8" ?>
    <plist version="1.0">
    <Main_Screen>
    <row>
    <btn_name>Buyer Programs</btn_name>
    <string>Answer your client’s difficult .</string>
    </row>
    <row>
    <btn_name>Seller’s Programs</btn_name>
    <string>What do sellers want s needs.</string>
    </row>
    </Main_Screen>
    <abssas>
    <row>
    <btn_name>dat Programs</btn_name>
    <string> your client’s </string>
    </row>
    <row>
    <btn_name>my Programs</btn_name>
    <string> sellers want s needs.</string>
    </row>
    </abssas>
    </plist>
    What is the problem with this?

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    926

    Re: Cant Make instances with usercontrol

    The xml file is included on your project? Is it Build Action as "Content"?

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    19

    Re: Cant Make instances with usercontrol

    yess.I tried it did not work.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    926

    Re: Cant Make instances with usercontrol

    Quote Originally Posted by yogeshg View Post
    yess.I tried it did not work.
    Can you provide a sample project? I dont seem to be able to replicate your problem.

  5. #5
    Nokia Developer Expert
    Join Date
    Oct 2007
    Posts
    441

    Re: Cant Make instances with usercontrol

    Hi yougeshg,

    You shall not have any operation that may throw exception in UserControl constructor. This lines i think make troubles:
    Code:
        Popup popup = new Popup();
        tutorial tut = new tutorial();   //another usercontrol
    If you like to create a child control tree , do it in onLoaded event not in the constructor. This construction works nice in Designer view for me. Also you can check Troubleshooting WPF and Silverlight Designer Load Failures
    Code:
    XAML:
             <UserControl x:Class="jailbreaker.BoardControl"
               Loaded="OnLoad">
    
                <controls:PivotItem Header="Start">
                    <Grid>
                        <my:BoardControl />
                    </Grid>
                </controls:PivotItem>
    CS:
           public BoardControl()
            {
                InitializeComponent();
            }
    
            void OnLoad(object sender, RoutedEventArgs e)
            {
                try
                {
                    accelerometer = new Accelerometer();
                    timer = new DispatcherTimer();
    //...................
                    accelerometer.Start();
                    timer.Start();
                }
                catch (Exception ignore)
                {
                }
            }
    do not forget to suppress possible exception in Designer surface with try/catch block , see above
    Last edited by izinin; 2012-08-19 at 18:29.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Location
    India / Singapore
    Posts
    549

    Re: Cant Make instances with usercontrol

    Hi,
    you can use my article as a reference.
    http://www.developer.nokia.com/Commu..._Windows_Phone
    Examine the header of the MainPage.xaml to see if you have a link to the custom usercontrol you have created.
    Twitter - manikantan_k
    Just in --

  7. #7
    Nokia Developer Expert
    Join Date
    Oct 2007
    Posts
    441

    Re: Cant Make instances with usercontrol

    Hi manikantan

    The problem is not in creating and use UserControl . Sometimes WPF designer preview pane is not able to render your application page because your UserControl implementation does not follow design guide "Writing Code for Design Time". In that case WPF designer and application running on device or emulator behaves differently., your application is not broken but you cannot use the page preview

    Regards,
    Igor

Similar Threads

  1. app multiply instances
    By vladest in forum Nokia N9
    Replies: 3
    Last Post: 2011-12-21, 12:33
  2. 2 emulator instances simultaneously
    By Lucky Luke in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2011-11-01, 10:52
  3. Multiple Canvas instances
    By deafbat in forum Mobile Java General
    Replies: 0
    Last Post: 2010-07-16, 07:54
  4. How many player-instances can I prefetch on N95?
    By fluffyangi in forum Streaming and Video
    Replies: 2
    Last Post: 2008-07-17, 11:32
  5. creating new instances.
    By smb101 in forum Mobile Java General
    Replies: 1
    Last Post: 2003-12-16, 11:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×