Dashed line in Xaml

silverlight — Szili @ 5:04 pm

Maybe I’m the last one on Earth figuring this out, but here it is:


<Path StrokeDashArray=”1,1″

More on the StrokeDashArray and creating dashed line from code here.

Beware the decimal separator

code, silverlight — Szili @ 3:18 pm

The clash between decimal separators, double values and application culture already made Point type a victim. Today I found abound another one..

I had an iframe positioned above my silverlight control. Its dimensions was controlled from C# managed code (with the use of System.Windows.Browser library).
Or at least it should have been.

ERROR:

No matter I gave the right double values to set the iframe’s width, it just didn’t changed:

Iframe.SetStyleAttribute("width", value.ToString() + "px");

SOLUTION:

After a few rounds of debugging I found the solution. The problem was caused by the decimal separator being a comma instead of a point.

The fix is the same as with the Point type:

Iframe.SetStyleAttribute("width", value.ToString(System.Globalization.CultureInfo.InvariantCulture) + “px”);

Fear Blend 2 and keep your Xaml dry

code, silverlight — Szili @ 10:15 am

Okay, I like Blend 2, but it has its tricks..

A control’s xaml when was loaded in its constructor threw a Catastrophic failure.

I designed the control in Blend 2 without touching the xaml’s source. It was a pretty simple graphic, four rectangles in a canvas.
All had unique names so the problem wasn’t related to namescopes.

To cut a long story short it occurred to me, that one rectangle had three spaces after the value in its height property. Fixing this solved the problem.

The full Exception info after the jump.

(more…)

Loading libraries run-time

code, silverlight — Szili @ 12:16 pm

I’m working on an application with the ability to upload and run Silverlight 1.1 gadgets. This means my program needs to be able to load assemblies in run-time.

After several tests and an e-mail exchange with an MS Evangelist it seams like it’s impossible.

UPDATE: Here is how I managed to do it. The trick is that the xaml downloads and loads its assembly automatically.
void DownloadXamlFile()
{
GadgetXamlDownloader.Completed +=
new EventHandler(GadgetXamlDownloader_Completed);
GadgetXamlDownloader.Open(
“GET”, new Uri(“./Gadgets/TestGadget/Page.xaml”, UriKind.Relative));
GadgetXamlDownloader.Send();
}


void
GadgetXamlDownloader_Completed(object sender, EventArgs e)
{
ObjectFromXamlString(GadgetXamlDownloader.ResponseText);
}


void
ObjectFromXamlString(string XamlString)
{
DependencyObject Gadget = XamlReader.Load(XamlString,true); //Namescoping is turned on
Gadget.SetValue(
Canvas.TopProperty,this.Height/2-(Gadget as Canvas).Height/2);
Gadget.SetValue(
Canvas.LeftProperty, this.Width / 2 - (Gadget as Canvas).Width / 2);
this.Children.Add(Gadget as Visual);
}

My old failed tests after the jump, they might be useful.

(more…)

My work and Madrid

personal, silverlight — Szili @ 6:46 pm

Monkey Invasion!

draw, silverlight — Szili @ 11:02 pm

Monkey Invasion screenshot

Grab and throw the monkeys before they reach the paintings!

My friend and I wrote this Silverlight game for an MS competition.

Check out the game here:
http://www.szili.net/sourcesofhope

And if you like it please vote for it:
http://www.flickr.com/photos/szili/1518833612/

Thanks, Szili

PS. The source code will be available next week.

UPDATE1: There seams to be a problem with the Silverlight Streaming service. I will check the code as fast as I can.

UPDATE2: Streaming had a short hick up but it seams ok now.

UPDATE3: The source. A junk and in Hungarian. There will be an Update4 with a polished English version with comments and stuff..

NoteToMyself: Xaml stream is null

code, silverlight — Szili @ 11:39 am

If your Xaml stream doesn’t load, chances are:

  • Your Xaml reference isn’t pointing correctly to the Xaml file.
  • Your Xaml is not valid.
  • Your Control is not set to be an Embedded Resource.
  • InitilazeFromXaml(…) is not in the lowest controls’ contructor in your inheritance tree.

NoteToMyself: Frameworkelement and System.ArgumentException

code, silverlight — Szili @ 9:06 am

Just a reminder to myself.

  • Something is wrong with the names
  • You are trying to add the Frameworkelment as a child, but it’s already a child of someone else, and you haven’t removed it.
  • It’s null.

Silverlight Loaded Event and Object Initializers

code, silverlight — Szili @ 12:38 pm

Got into a tricky situation today.

I used the new C# Object Initializer “syntactic sugar” to initialize my object:
MyType MyObject = new MyType{MyBool=true};

At the same time I used the property as a condition in MyObject.

First I used it in the constructor, but it didn’t work since the new value of the property was given only after the constructor ran (pretty logical).

Then I used it in the Loaded Event, but the event fires way after I need the changes made by MyBool.

Three things learned:

  • The Object Initializer give value to the properties after the object is instantiated.
  • I thought the Loaded event fires right after the object is instantiated. It’s not.
  • I’m still a Noob.

(The solution was to give parameters to my constructor and give value to the property through it. But this is not the important part.)

Giving value to a Point

code, silverlight — Szili @ 6:05 pm

Point class constructor problems can be caused by regional settings. Dot vs. comma stuff: http://silverlight.net/forums/t/4142.aspx

I’m still hopeless!!!

Solution 1
Can’t really call it a solution. Just inverses the problem..

double x = Convert.ToDouble("11,5");
double y = Convert.ToDouble("0,44");
Point TestPoint = new Point(x,y);

Solution 2
Didn’t really work for me either. I guess it’s my fault, but i had problem with constructing Point from results of calculations:

http://www.codeproject.com/csharp/floatparse.asp

Solution 3
My solution. It’s cool until you use it to create a new point. But as you try to give value to a Point property, like GradientOrigin it fails.

double x;
string _x = (2.0 / 3.0).ToString(System.Globalization.CultureInfo.InvariantCulture);
x = double.Parse(_x, System.Globalization.CultureInfo.InvariantCulture);
double y;
string _y = (1.0 / 2.0).ToString(System.Globalization.CultureInfo.InvariantCulture);
y = double.Parse(_y, System.Globalization.CultureInfo.InvariantCulture);
Point TestPoint = new Point(x,y);

Extensive tests with September refresh

(with no results…)

(more…)

« Previous PageNext Page »
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2012 Szili | powered by WordPress with Barecity