ive searched and searched the answer eludes me still. here is my code
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
namespace GTA_5_Guide
{
public partial class MainPage : PhoneApplicationPage
{
//Constructor
public MainPage()
{
//Loads the page onto the screen
InitializeComponent(); //This is were the error is thrown
}
}
}
the error thrown is a "A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll"
everything was working fine till I decided not to use a web page I had found in my project anymore noe it throws this error
9 times out of 10 this is usually just the designer file not inheriting the same Type.
Make sure your MainPage root XAML control is in-face <phone:PhoneApplicationPage...
Related
I am building a form where i can drag and drop button controls.
I followed the tutorial from this link but the code generates an error difficult for me to debug.
Syntax Error
Error code CS1030, "The name 'Helper' does not exist in the current
context
I have tried adding and removing namespaces, using System and using System.Drawing but the same error code is still present.
In a much more extensive code like the actual example, Helper.ControlMover does work, and it is very easy to use. What exactly am i missing in the code below?
Thank you for your time and help.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MovingControls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Helper.ControlMover.Init(this.button1);
}
}
}
I get a strange error message when using viewState on a web page. Using example code from Microsoft generates this error on ViewState["Text"]:
Error 17 Cannot apply indexing with [] to an expression of type
'method group'
It seems the error is not in the code, but in config or something.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using OfficeOpenXml;
using vaCommonLibrary;
public partial class lista : System.Web.UI.Page
{
public String Text
{
get
{
object o = ViewState["Text"];
return (o == null)? String.Empty : (string)o;
}
set
{
ViewState["Text"] = value;
}
}
I get another error further down in my code:
ViewState["SortDirection"] = sortDirection;
gives
Error 1 Invalid token '[' in class, struct, or interface member
declaration
Problem solved.
Your second error sounds like that code isn't in the right place
Absolutely correct. The code was right, but further down in my code there was a { missing after an IF-statement, which caused later parentheses to mismatch leading to "strange" errors. I should have seen that, but I'm kind of new to C#, and just started to migrate all my VB.NET code to C#.
Thanks.
I'm not experienced with C#, but I got the basics down. Now I'm trying to download videos from YouTube with the Video Library (in the VS package manager: Install-Package VideoLibrary).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using VideoLibrary;
namespace TubeDemo
{
public partial class MainWindow : Window
{
string link = "https://www.youtube.com/watch?v=8SbUC-UaAxE";
string link2 = "https://www.youtube.com/watch?v=BlRqTNkgEuo";
public MainWindow()
{
InitializeComponent();
}
void SaveVideoToDisk_Click(object sender, EventArgs e)
{
var youTube = YouTube.Default; // starting point for YouTube actions
var video = youTube.GetVideo(link2); // gets a Video object with info about the video
File.WriteAllBytes(#"C:\testfire\" + video.FullName, video.GetBytes());
}
}
}
Above functions SaveVideoToDisk_Click gets called from a .xaml button, which works fine. But not every video works OK. video.URI gets awfully big, over 800 characters. Some of the URLs turn out to cause the video.URI to throw an exception:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
In the code provided, passing link as argument throws while passing link2 works just fine.
Can I fix this?
If not, how should I handle these exceptions? Just try, catch and report or is checking before a better idea?
I've search the forum, but I coundn't find anything that quite satisfied me.
In Microsoft Visual Studio 2010, when I try to add a WPF User Control I get this error:
"Value cannot be null. Parameter name: objectType"
Then when I want to select the hosted content, I get this error :
"An error occured trying to add references for type 'PolyPuttZe.GameCanvas', or finding the type. Make sure the project references are correct."
I followed this tutorial : http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms
Thanks!
EDIT:
This is the code I wrote :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
namespace PolyPuttZe
{
public partial class Game : Form
{
public Game()
{
InitializeComponent();
}
}
}
Here's a more useful answer for the next person that has this issue - you need to create your WPF user control and build the solution first. Then open/create the form and add an Element Host and set it to your control. This is likely what the accepted answer means as starting over would work as well if you create the WPF control first.
I have the following code
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
// Required to initialize variables
InitializeComponent();
}
}
}
where do I find the code for this InitializeComponent(); I have no idea what its doing. thanks
InitializeComponent is implemented on the other side of your partial class. It is auto-generated code, and determines the components and controls used on your page, it's positions, etc.
If you want to look at the implementation you can put your cursor on it's name and hit F12 (only works on VisualStudio :)
Also, you can check the official documentation here or this nice answer
It's provided by the designer-generated code created from your XAML. You can look for this in the obj directory - it'll be called MainPage.g.cs IIRC. Normally you don't need to look at this; just keep the InitializeComponent call where it is, and know that the designer will do the relevant magic for you :) (Obviously it's good to know what the magic is really though.)
As you can see from this line of code :
public partial class MainPage : UserControl {
this is a Partial class, so not all code is showed in this file.
If you use Visual Studio you can use F12 (or right click and Go To Definition) and the IDE go directly to the method.