|
Help me Convert this WPF to Silverlight
I am interested in a Charles Petzold C# example that shows how to do a fisheye effect ( http://www.charlespetzold.com/blog/2009/05/Realizing-a-Fisheye-Effect-in-Silverlight.html ). The XAML code samples are in WPF but I want to try this in Silverlight.
When I try to create the XAML code in Silverlight, the compiler complains in two locations:
<Style TargetType="{x:Type Button}">
Error 1 The type 'x:Type' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
<Style.Triggers>
Error 2 The attachable property 'Triggers' was not found in type 'Style'.
How do I convert this to Silverlight?
|
|
|
|
|
Try the correct forum.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi,
I created a dll as a plugin to another program. I would like to know the best technique to debug this dll without putting it in the parent applications "plugin" folder and launching that application.
I'd like to be able to debug it in Visual Studios like I have done in the past. This is the first dll I have built. How can I hit "F5" in Visual Studios and have it compile the form (GUI) portion of the DLL? I have tried inserting
public static void Main(string[] args)
{
Setup();
}
but there is a conflict because the method "Setup()" cannot be made static. Thanks for reading!
public void Setup()
{
int startChannelInt = Convert.ToInt16(this.g_setupNode.Attributes["from"].Value) - 1;
SetupDialog dialog = new SetupDialog(this.g_channels, startChannelInt);
if (dialog.ShowDialog() == DialogResult.OK)
{
int selection = dialog.selectedChannel;
XmlNode contextNode = this.g_setupNode.SelectSingleNode("Settings");
contextNode.RemoveAll();
XmlNode newContextNode = Xml.SetNewValue(contextNode, "ChannelIndex", selection.ToString());
Xml.SetAttribute(newContextNode, "Attribute", "value");
}
dialog.Close();
}
|
|
|
|
|
Setup must be a method inside a class, so you need to instantiate an instance of this class - at this point, you can use this instance to call Setup.
|
|
|
|
|
Hi Pete,
Thanks for the response ... Are you saying that as long as I wrap all of the code in a class, I'll be able to debug in VS?
|
|
|
|
|
You can also launch & debug an "external program" (with your DLL loaded) in Visual Studio (not in the Express version though).
Breakpoints and all that stuff will still work.
|
|
|
|
|
Hi Harold,
Thanks for the response. I only have the express version, I did try a break point, but since I can't call Setup(), it just cycles right through and closes.
|
|
|
|
|
Well yes, the process wasn't being debugged.. you can work around this by calling Setup from a small program of course, but if you could just get the Pro version it gets much easier especially if you ever want to debug a DLL that has complex interaction with its parent-application. If you're a student you can get it for really cheap (or maybe it was free, I don't remember - free is pretty cheap too though).
|
|
|
|
|
turbosupramk3 wrote: I would like to know the best technique to debug this dll without putting it in the parent applications
For starters your first step shouldn't be debugging. It should be testing.
The way I unit test is to use Nunit which you can google for.
You can use that or write your own application. That application is NOT part of the dll nor would your unit test code be part of the dll.
You create a different project, and myself I create a different solution as well. That project contains the unit test code. The unit test code calls the code in the dll to test parts of it and also to test the total functionality.
Once you do that, then if you have a unit test that fails then you have the code, the unit test code, which you can then debug.
|
|
|
|
|
Hi, thanks for the reply. I've always lumped testing and debugging into the same pot?
I'll go read about Nunit now, wikipedia doesn't have a very lengthy explanation on it, but it appears it is a wrapper for DLL's?
|
|
|
|
|
turbosupramk3 wrote: but it appears it is a wrapper for DLL's?
Yes and no.
The point of it is to allow a framework for writing unit tests. One need only use a very few parts of it to achieve quite a bit towards that. It also exists for other languages.
To achieve that it provides a console app and gui either of which can be used to run a suite of unit tests. And it is that part to which the answer to your question is yes.
However keep in mind that unit testing is the goal. Uunit is just one way to achieve that.
|
|
|
|
|
Very good point - gets my 5.
The only difference is that I would keep the tests in the same solution, simply because it is easy to co-ordinate with Subversion than two separate solutions. I can see where you are coming from though.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I'm having a problem retrieving an XML value with C#. I need to grab the value 0 for the probability of tornadoes, but I'm getting errors.
Here's the XML code that I'm loading:
-<convective-hazard>
-<severe-component time-layout="k-p24h-n1-4" units="percent" type="tornadoes">
<name>Probability of Tornadoes</name>
<value>0</value>
</severe-component>
</convective-hazard>
There's actually 5 different convective-hazard lists that I'm loading.
Here's my C# code:
XmlDocument xmlWeatherDocument = new XmlDocument();
xmlWeatherDocument.LoadXml(xmlWeatherData);
if (!(xmlWeatherDocument == null))
{
try
{
XmlNodeList weatherParameterList =
xmlWeatherDocument.SelectNodes("dwml/data/parameters");
XmlNodeList convectiveHazardList =
weatherParameterNode.SelectNodes("convective-hazard");
// Process the potential hazard conditions (5 in this case)
foreach (XmlNode convectiveHazardNode in convectiveHazardList)
{
// In this case three
for (int i = 0; i < convectiveHazardNode.LastChild.Attributes.Count; i++)
{
if (convectiveHazardNode.LastChild.Attributes[i].Value == "tornadoes")
{
probabilityOfTornadoes =
Convert.ToInt32(convectiveHazardNode.LastChild.InnerText);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception Error: " + ex);
Console.WriteLine("<br />");
}
}
The probabilityofTornadoes variable contains "Probability of Tornadoes0".
I'm still a newbie at this stuff, so it might seem simple to some, but not me!
Thanks for all the help!
Cindy
|
|
|
|
|
This seems to work:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
doc.LoadXml (
@"
<dwml>
<data>
<parameters>
<convective-hazard>
<severe-component time-layout='k-p24h-n1-4' units='percent' type='tornadoes'>
<name>Probability of Tornadoes</name>
<value>0</value>
</severe-component>
</convective-hazard>
</parameters>
</data>
</dwml>
" ) ;
System.Xml.XmlNode nod = doc.SelectSingleNode ( "dwml/data/parameters/convective-hazard/severe-component[@type='tornadoes']/value" ) ;
System.Console.WriteLine ( nod.InnerText ) ;
Also:
0) Don't use Convert.ToInt32 -- use Int32.Parse or (preferably) Int32.TryParse
0.0) (Don't use Convert at all, except for Convert.ChangeType )
1) I wouldn't trust .LastChild to give me what I want.
2) Use XPath rather than looping and testing.
Edit, other niggles:
3) if (!(xmlWeatherDocument == null)) ==> if (xmlWeatherDocument != null)
4) Console.WriteLine("Exception Error: " + ex) ==> Console.WriteLine("Exception Error: {0}" , ex)
modified 29-Dec-11 15:18pm.
|
|
|
|
|
I didn't know that I shouldn't use Convert. I will try to remember to use Parse all the time.
What about when I'm trying to convert an integer to a string variable? I'm not getting the parse option with string.
When you say xPath, is that "dwml/data/parameters/convective-hazard/severe-component[@type='tornadoes']/value" ?
If so, I think it will make the code very messy as this is a pretty large XML document that I have to process.
|
|
|
|
|
Cindy MCS wrote: shouldn't use Convert
That's mostly personal preference, but in most cases Convert simply calls a Parse method so you might as well cut out the middleman. (And it looks VBish.)
Cindy MCS wrote: to convert an integer to a string
Use ToString or, as in the case of Console.WriteLine , let the system do it.
Cindy MCS wrote: When you say xPath ...
Yes, and it's the prefered way to query an XML document.
Cindy MCS wrote: this is a pretty large XML document
You can access different chunks separately -- as you do in your post when selecting the dwml/data/parameters part.
|
|
|
|
|
I'm not too sure about your code - there are a couple of worries here:
1) What is weatherParameterNode - you neither declare nor set it. If you mean weatherParameterList (and I suspect you do) then it doesn't have a SelectNodes method.
2) Why are you assigning a numeric value to probabilityOfTornadoes ? And just how did it get from a numeric value to "Probability of Tornadoes0" if it is a numeric value?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
The weatherParameterNode contains all the nodes within the weatherParameterList.
This line of code is right after declaring weatherParameterList:
foreach (XmlNode weatherParameterNode in weatherParameterList)
The probabilityOfTornadoes was of type integer, but I was receiving errors because it had invalid character values, so I changed the type to string for testing purposes, it just wasn't posted that way earlier.
|
|
|
|
|
Hey everyone,
I've been writing a script to monitor availability of registering steps (7 steps).
each step requires a POST request.
I want to make sure it passes well.
I am sending a post request but when I check the response page it seems to be the same one and not the next page!
Here is my code: (I changed the URL to eBay registration so it will be easier if someone wants to check), it only needs asks to change the EMAIL/Password/UserID details inside POST request)
static void Main(string[] args)
{
string url = "https://scgi.ebay.com/ws/eBayISAPI.dll?RegisterEnterInfo";
string method = "POST";
string postdata = "firstname=Test&lastname=Tester&address1=teststreet+20&zip=56683&st_ct=Tenstrike%2C+MN&countryid=1&email=secret1234%40walla.co.il&retype_email=secret1234d%40walla.co.il&dayphone1=789&dayphone2=678&dayphone3=6786&userid=secretrotd442017771&pass=Qq123456&rpass=Qq123456&canned=4&myanswer=Paffi&birthdate2=2&birthdate1=17&birthdate3=1976&frmaction=submit&mode=1&country=&MfcISAPICommand=RegisterEnterInfoV4&city=Tenstrike&state=MN&isSug=true";
string file = sendRequest(url, method, postdata);
TextWriter tw = new StreamWriter("C:\\WebPost_Response.htm");
tw.WriteLine(file);
tw.Close();
}
public static string sendRequest(string url, string method, string postdata)
{
WebRequest rqst = HttpWebRequest.Create(url);
rqst.Method = method;
if (!String.IsNullOrEmpty(postdata))
{
rqst.ContentType = "application/xml";
rqst.ContentType = "application/x-www-form-urlencoded";
byte[] byteData = UTF8Encoding.UTF8.GetBytes(postdata);
rqst.ContentLength = byteData.Length;
using (Stream postStream = rqst.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
postStream.Close();
}
((HttpWebRequest)rqst).KeepAlive = false;
StreamReader rsps = new StreamReader(rqst.GetResponse().GetResponseStream());
string strRsps = rsps.ReadToEnd();
return strRsps;
}
else
{
return "Failed";
}
}
So, If anyone can tell me how I make sure to get the next page I would be very grateful!
Thanks
|
|
|
|
|
Are you aware you're disposing of the post stream before you are getting a response to it? I'd enlarge the scope of the using construct....
|
|
|
|
|
Do you mean something like this? (Didn't work..)
if (!String.IsNullOrEmpty(postdata))
{
rqst.ContentType = "application/xml";
rqst.ContentType = "application/x-www-form-urlencoded";
byte[] byteData = UTF8Encoding.UTF8.GetBytes(postdata);
string strRsps = "";
rqst.ContentLength = byteData.Length;
using (Stream postStream = rqst.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
((HttpWebRequest)rqst).KeepAlive = false;
StreamReader rsps = new StreamReader(rqst.GetResponse().GetResponseStream());
strRsps = rsps.ReadToEnd();
postStream.Close();
}
|
|
|
|
|
Yes, that is what I was hinting at. Now it looks fine, except I'm unsure about the KeepAlive thing; I have similar code working, but that doesn't set KeepAlive false.
BTW:
1) don't reply to yourself, nobody gets notified when you do.
2) don't say "doesn't work", always give an accurate description (behavior, symptoms, error messages, ...)
|
|
|
|
|
Check the content of the response. Chances are you are failing to correctly fill out the form (i.e. you missed out a parameter or made a typo in a parameter name) and it's been returned to you with validation error messages.
It's possible that you need to fake the Referer header as well, but make doubly sure you're submitting the right things before resorting to that.
|
|
|
|
|
Hello people I wanna know how you could calculate how hard your central processor could really work at using C#. I thought I could use a timer called "calc_reset" with an interval of 1000 and another one called "incr" with an interval of 1 then allow it to increase uncontrollably by allowing it to calculate random adding, subtracting, multiplying and division equations and allow the timer "calc_reset" to take the value (of completed equations, maybe correct ones aswell...) from timer "incr" and reset it after that. Any suggestions would be greatly appreciated .
Regards,
Brandon T. H.
|
|
|
|
|
The result you'd get would be pretty meaningless..
What is the actual metric you want to know?
|
|
|
|