DCSIMG
October 2007 - Posts - Justin myJustin = new Justin( Expriences.Current );

October 2007 - Posts

Expression Blend 2 For Silverlight - Extensibility suggestions

It's a well known fact that Blend 2 has a very unique extensibility strategy - None.
What does google have to say about that you ask?

image

868 google results for "Expression blend extensibility".

What's the problem?

image 

1,230,000~ results for "Visual studio extensibility".

I've got several real-world projects going on with Silverlight today and I'm working closely with Silverlight designers using Expression Blend.
Whenever I look at Blend all I can think is "This could be 50 times better if the community could add what they need".
I can't help it, I'm used to having extensibility in Visual Studio!

image

 

So I've talked it over with people from the Expression Blend team.
They have a short and familiar problem - They need to be focused so they can get as many useful things to the RTM version.

I thought about it long and hard (and trust me, I don't think very often) and I've came up with this extensibility modal.

 

1. Custom Property Grid designers (i.e. Data Pane in Blend).

This is the Blend answer that will easily replace Visual Studio's TypeConverter's and UIEditor's.

This is the Blend Property Grid:
image

When I create a custom property, currently there's very primitive support for custom properties.
Here's what I want from the Blend team - Let the developer decide which property grid designer to use.

The developer needs control of two distinct areas for each property - (1) Right and (2) Down.

image

How can we give the developer control over these areas?
Let him say exactly what they are and let him return their XAML value.

Let's look at some code, shall we.

    public class SomeSilverlightUserControl : Control

    {

        public SomeSilverlightUserControl()

        {

            System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("SilverlightProject1.SomeSilverlightUserControl.xaml");

            this.InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd());

        }

    }

This is our normal Custom Silverlight UserControl.

 

We'll expose a new property.

        public string someProperty

        {

            get;

            set;

        }

(C# 3.0 short property syntax for those of you who aren't familiar with it)

Let's add this control to a Silverlight Page in Blend.

image

We can see that in the right-bottom corner, "someProperty" is shown using a TextBox.
What if I'd like to have something else?
maybe my own custom TextBox? (Masked Edit TextBox, for instance)
maybe a DropDownList with pre-loaded values?
maybe even a button to open a new Dialog?

So, this is my purposed solution. Blend folks, give us this interface:

namespace Expression.Blend.Extensibility

{

    public interface IPropertyGridDesigner<T>

        where T : UIElement

    {

        bool HasCustomRightArea();

        Control GetCustomRightArea(T CurrentXamlElement);

 

        bool HasCustomBottomArea();

        Control GetCustomBottomArea(T CurrentXamlElement);

 

        string GetXamlValueForPropety();

    }

}

Here's how we can do EVERYTHING with this interface.

 

        [CustomPropertyDesigner(typeof(PhoneNumberPropetyGridDesigner))]

        public string PhoneNumber

        {

            get;

            set;

        }

 

    public class PhoneNumberPropetyGridDesigner : IPropertyGridDesigner<Control>

    {

        public bool HasCustomRightArea()

        {

            return true;

        }

 

        private MaskedEditorTextBox tbx;

        public Control GetCustomRightArea(Control CurrentXamlElement)

        {

            tbx = new MaskedEditorTextBox("(999)-999-9999");

            return tbx;

        }

 

        public bool HasCustomBottomArea() { return false; }

        public Control GetCustomBottomArea(Control CurrentXamlElement)

        {

            throw new NotImplementedException();

        }

 

        public string GetXamlValueForPropety()

        {

            return tbx.Text;

        }

    }

Inside the "GetCustomArea" methods, we can initialize whatever we'd like (Buttons that open Dialog boxes, DropDownLists with values per the current XAML Element and so on).

One simple 5 method interface implemented in Blend can make Blend's Property grid amazingly better.

 

2. Custom Designers

This one is a replacement for Visual Studio's Custom Designers, works on the same principle but is much simpler.

Here's how every Silverlight User Control looks like today in Blend:

image

Yep, I blank blue line.

Let the developer decide what XAML is going to get rendered for his control in Blend.

Here's the interface we need the blend folks to provide:

namespace Expression.Blend.Extensibility

{

    public interface IControlDesigner<T>

        where T : UIElement

    {

        bool HasCustomDesignerElement();

        UIElement GetDesignerElementForControl(T currentControlToRender);

 

        bool HasCustomDesignerXaml();

        string GetDesignerXamlForControl(T currentControlToRender);

    }

}

Using this interface we can either return a XAML string or a Root Canvas UIElement that will be the default display for any user control.

    [CustomDesigner(typeof(CustomSomeSilverlightUserControlDesigner))]

    public class SomeSilverlightUserControl : Control

    {

  ...

    }

And the designer would like this:

    public class CustomSomeSilverlightUserControlDesigner : IControlDesigner<SomeSilverlightUserControl>

    {

        public bool HasCustomDesignerElement()

        {

            return true;

        }

 

        public UIElement GetDesignerElementForControl(SomeSilverlightUserControl currentControlToRender)

        {

            Canvas newCanvas = new Canvas();

            newCanvas.Children.Add(new TextBlock("Hello world"));

            return newCanvas;

        }

 

        public bool HasCustomDesignerXaml()

        {

            return false;

        }

 

        public string GetDesignerXamlForControl(SomeSilverlightUserControl currentControlToRender)

        {

            throw new NotImplementedException();

        }

 

    }

Or we can just return the XAML code, like this:

    public class CustomSomeSilverlightUserControlDesigner : IControlDesigner<SomeSilverlightUserControl>

    {

        public bool HasCustomDesignerElement()

        {

            return false;

        }

 

        public UIElement GetDesignerElementForControl(SomeSilverlightUserControl currentControlToRender)

        {

            throw new NotImplementedException();

        }

 

        public bool HasCustomDesignerXaml()

        {

            return false;

        }

 

        public string GetDesignerXamlForControl(SomeSilverlightUserControl currentControlToRender)

        {

            return "<Canvas><TextBlock Text=\"Hello world\"><Canvas>";

        }

    }

 

And these two methods would ultimately determine what'll show up on the Blend Design Surface.

 

Everything that's described in this article in very rudimentary and isn't polished.
But even in this basic form - These suggestions would make Blend a far better tool as it would enable Developers to empower Designers with better tools.

I'd love it if people could comment with better suggestions or even start a discussion on this one.
Blend has to get better & fast, but how do YOU think that could be accomplished?

 

 

רועי אושרוב מחפש עבודה - תגנבו אותו

רועי אושרוב כתב בבלוג שלו שהוא עוזב את סלע ומחפש עבודה.
 
לכל מי שמחפש יועץ טכני בכיר שיצמד לפרוייקט בצורה שוטפת, זה האיש שלכם.
 
הנה הוראות הפעלה:
1. להשיג עגלת קניות. (מזהב, כי הוא רועי אושרוב ומגיע לו את הטוב ביותר)
image
 
2. למצוא הופעה ציבורית של רועי. למשל, יש את כנס המפתחים ב-27.11.2007.
image
 
 
3. להרים אותו ולזרוק מהר לתוך העגלת קניות.
image
(אולי ה-Photoshop הכי גרוע שבוצע אי-פעם בעולם, אבל עשיתי אותו ב-Paint.Net שזאת תוכנת עיצוב שכתובה בדוט נט)
 
ועכשיו ברצינות, מעבר לבדיחה הברורה על "לקנות את רועי אושרוב" שהייתי חייב לעשות.
 
רועי אושרוב הוא בן-אדם נהדר, ויותר מפעם אחת כבר יצא לאנשים לשמוע אותי אומר בדיוק את זה.
מעבר לזה, יש לו ראש טכני חריף ומחודד, כישורי אנוש מדהימים ושנים של וותק בתחום הזה.
 
לפי הפוסט שלו, רועי מתלבט בין כמה אפשרויות בחיים כרגע, להישאר יועץ טכני עצמאי, לחזור להיות שכיר (CTO) או להקים חברת סטארט-אפ.
אני מכיר טוב מאוד את ההתלבטויות האלו ומבין באיזה עמדה רועי נמצא כרגע.
 
אז אם אתם מחפשים מישהו שהוא הסוכר על הדובדבן שעל הקצפת שנמצאת על העוגה - תדברו עם רועי.
 
 

בשר ובלוגים - זיווג שנולד משמיים

אז תקשיבו, יש לי רעיון לסטארט-אפ.

ישר אחרי כנס טכנולוגי ניקח בלוגרים שיודעים דוט-נט ,נעביס אותם בבשר ואז נוציא מהם סודות עסקיים וטכנולוגיים.

פירוק התוכנית המבצעית:


1. ב-27.11.2007 בבוקר יש כנס טכנולוגי ענק עם מיטב המרצים בארץ.

image


2. בשעות אחה"צ בערך בשעה 18:00 תיכנס חוליה של 50 מפתחים למסעדה בשרית משובחת באזור.
(ספציפית, "עד העצם" באייר-פורט סיטי איפה שהכנס)

image

image


3. נתיישב בנקודות אסטרטגיות ברחבי המסעדה תוך כדי התמקדות בגורמים הפעילים בעלי חשיבות טקטית: כניסת חזית, יציאה אחורית והגריל.

image

 

4. בשעה 18:15:00 הטקטית, הגורם המבצעי הבכיר בשטח ("ג'סטין-יוסף אנג'ל") ישאל את "אורן עייני" (ראה תיק נספח) שאלה פרובקטיבית.
השאלה: "אורן, אז מה דעתך על התשתית MVC החדשה של ASP.Net?
נכון שזה גורם לפיתוח ב-ASP.Net להיות טסטבילי ויותר טוב מ-MonoRail?" 

image

5. תשובתו של אורן, תגרור דיון בקרב כל 50 המפתחים סביב השולחנות השונים ובמהלך הוויכוח מידע טכני ועסקי יזרום כ-יין.
בנוסף, יין מהול ב-Scopolamine יחולק לכל המשתתפים.

 image

 

זה פחות סטארט-אפ, יותר מבצע טקטי פרימיטיבי (מאוד, ממש מאוד) של השב"כ. למישהו יש מנורת חקירות להביא?

Silverlight 1.1 Hebrew and Arabic Language Support - SilverlightRTL

Presenting -   Silverlight 1.1 Hebrew & Arabic Language Support.
Since I've started working on Silverlight projects in Israel I've got one constant request from every customer - "We need Hebrew support!".
So, we developed a Silverlight component that enables just that - Hebrew & Arabic Right-to-left & Align-to-right support.

* www.Codeplex.com/SilverlightRTL - The codeplex project page
* www.JustinAngel.Net/SilverlightRTL - online demo & lab
* http://ttvv.tv/users/publicftp/justinangel/SilverlightRTL.wmv - A webcast showing everything done in this article

 

Standard hello world examples

This is how we would expect each "hello world!" sample to render: (using the browser rendering engine)

שלום עולם!
مرحبا عالم!
hello world!


As we can all see - English text is aligned to left and is written Left-to-Right (LTR).
But Hebrew & Arabic are written aligned to right and are written Right-To-Left (RTL).

 

So let's see the "hello world!" samples In Blend:

image

(You can see all texts are aligned-to-left and are formatted by the OS and not by Silverlight)

 

However, when running the Silverlight 1.1 application in the browser we get this:
image

What??? The texts are all jumbled!
even if you don't know how to read Hebrew & Arabic - you can see the two examples don't look the same.

Now let's see the Texts render properly using our new Silverlight 1.1 Hebrew & Arabic Language support:

image

 

We'll sum up the comparison we just did:

Rendering Comparison

Normal Silverlight 1.1

RTL (Right-to-Left): Not Supported
Align-to-right: Not Supported
image
Silverlight 1.1 Hebrew &
Arabic Language support

RTL: Supported
Align-to-right: Supported
image

HTML

RTL: Supported
Align-to-right: Supported

שלום עולם!
مرحبا عالم!
hello world!
Blend

RTL: Edit Mode only
Align-to-right: Edit mode only
image

 

Let's see if our solution renders correctly some mixed text (Hebrew, Arabic, Numbers, punctuation and English).
We'll try to use Silverlight on this text:

שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012.

hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456. hello world 789.012. مرحبا عالم 123.456. hello world 789.012. שלום עולם 123.456.


Using the new Hebrew & Arabic support we get this in Silverlight on a TextBlock with a fire ForeGround image and black Background:
  image

And without our Hebrew & Arabic support we get this weird cross Hebrew & Arabic & English syntax:

image 

 

Instructions & feature overview:

1.       Setting up the RTL Extender

2.       RTL and auto align the whole page

 

Advanced features:

3.       RTL selected TextBlocks

4.       RTL TextBlocks on selected Canvases

5.       Excluding TextBlocks and Canvases from being RTLed

6.       Disabling the RTLExtender

7.       Auto align feature Explained

8.       Forcing aligning to right on all TextBlocks

9.       Never animate an RTLed TextBlock – animate only the parent Canvas.

10.   Never Rotate an RTLed TextBlock – rotate only the parent canvas.

11.   RTL a TextBlock by using C# code

12.   Programmatically use RTLed TextBlocks.

13.   Changing the TextBlock TextWrapping property from the Default. 

 

Setting up the RTL Extender

1.       Download  Binaries from: http://www.Codeplex.com/SilverlightRTL and extract the DLL (JustinAngelNet.SilverlightRTL.DLL).

image 

2.       Create a new "Expression Blend Orcas" project in Expression Blend 2 September preview.
clip_image001
image

3.       Add a reference to JustinAngelNet.SilverlighRTL.dll. (from JustinAngelNet.SilverlightRTL.zip)

 
image

 

4.       Open the Expression Blend Asset library and choose RTLExtender. (Asset Library à Custom Controls à RTLExtender).
clip_image004

clip_image005

image

 

5.       Place it anywhere on the form (doesn't matter where or what size)
clip_image007
clip_image008

 

 

RTL the whole page

1.       Once the RTLExtender has been added to form, all TextBlocks will be Right-to-left and Aligned to right.

2.       Simply add a TextBlock to the page, write some content in it.

clip_image009

3.       Run the sample.
clip_image010

 

RTL specific TextBlock/s

 

1.       Add another TextBlock to our page with Hebrew/Arabic.
clip_image011

2.       Give it a name.
clip_image012

3.        

4.       Choose the RTLExtender properties.
clip_image013 

clip_image014

 

5.       In TargetTextBlocksName write the ID of the TextBlock.

clip_image015

 

6.       Tbx1 should be the only TextBlock this RTLExtender RTL's.

clip_image016

 

7.       You can specify multiple specific TextBlocks like this:

clip_image017

 

RTL only TextBlocks on a specific canvas.

1.       Add one more TextBlock to the page (that's 3 by now), and group two of them to a canvas.
clip_image018

2.       Name the Canvas.

clip_image019

 

clip_image020

 

3.       Set TargetCanvasesName to our canvas/es.

clip_image021

 

4.       Only the TextBlocks nested somewhere on this canvas/es will be RTLed.

clip_image022

 

Excluding TextBlocks/Canvases from being RTLed

1.       Let's say we want to RTL the entire form besides some canvas/es or TextBlock/s.
We can exclude TextBlocks by using the ExcludedTextBlcoksName:
clip_image023

2.       And it will be the only one of the form not RTLed:
clip_image024

 

3.       Sames goes if we want to execlude specific Canvas/es.
clip_image025

 

4.       And the two textblocks on myCanvas won't be RTLed, but all others on the page will.

clip_image026

 

 

Disabling the RTLExtender

1.       Well, this is pretty straight forward. Marking "Disabled" will cause the RTLExtender to not RTL anything.

clip_image027

 

2.       And the result:

clip_image028

 

 

Auto Aligning feature

1.       Add a new TextBlock to the Page and write one sentence that starts in Hebrew/Arabic, press enter and one sentence that starts in english.

clip_image029
clip_image030

 

2.       I'll add a rectangle on the TextBlocks borders just so you see this feature better.
clip_image031

 

3.       Run the sample and you can see that all sentences starting with an RTLed language are Aigned to right and others are still aligned to the left.

clip_image032

 

4.       Same feature with more text:
clip_image033

5.       First sentence – starts with Hebrew à Aligned to right.

Second Sentence – starts with english à Aligned to left.
Third sentence – Starts with Hebrew à Aligned to right.
Fourth sentence – Starts with english à Aigned to left.

clip_image034 

 

 

Force Align to Right on all sentences (not based on first character)

1.       Set the "ForceAllParagraphsAsRTL" to true.
clip_image035

 

2.       Run the sample, and all paragraphs are aligned to right.

clip_image036

 

 

Animating an RTLed TextBlock – Only on Parent Canvas

 

All animations on TextBlocks that will be RTLed must be on the Parent Canvas or RTLExtender will throw an exception.

 

1.       Create a new storyboard that starts when the page loads up.

clip_image037
clip_image038

 

2.       Select a TextBlock that will be RTLed, and animate it some how. (let's say rotate it)

clip_image039

 

3.       Run the sample – Nothing happens.

clip_image040

 

4.       Open the test project in Visual Studio and run it from there.
clip_image041

 

5.       So we got an error message in VS2008 Beta2, telling us that we can't place ANY animations directly on the TextBlock.
We should group the TextBlock into a canvas.

clip_image042

6.       Change the animations to point to the Canvas instand of the Actual textblock.

clip_image043

 

Becomes:

 

clip_image044

 

7.       Rerun the sample and it will RTL correctly.

clip_image045

 

 

Transform Rotate RTLed TextBlock – only on parent canvas

No RotateTransform are allowed on the TextBlock that will be RTLed or RTLExtender will throw an exception.

 

1.       Let's take a TextBlock and rotate it.

clip_image046

 

2.       If we run the sample through Expression Blend we get non RTLed text:
clip_image047

 

3.       If we run the sample through visual studio we get the following exception:

clip_image048

 

4.       Let's place the TextBlock inside a Parent Canvas and rotate it instand.

clip_image049

 

clip_image050

 

5.       And when we run the Sample we get RTLed code:

clip_image051

 

Programmatic Access – RTL TextBlocks by Code:

1.       We can use the RTLExtender to RTL specific TextBlocks programmeticly. (let's say TextBlocks on included in "TargetTextBlocksName" or those dynamically created at runtime)

 

clip_image052

 

2.       And as we can see, it's not RTLed on the page:

clip_image053

 

3.       We’ll get a reference of the RTLExtender (or create a new one) and call the RTLTextBlock method.

clip_image054

 

clip_image055

 

4.       And when we run this code the Text is RTLed:

clip_image056

 

 

Programmatic Access – Using an RTLed TextBlock:

1.       Let's run this code:

clip_image057

 

clip_image058

 

 

2.       After a TextBlock has been RTLed it is no longer on the Xaml page.

clip_image059

 

clip_image060

 

3.       That's because it's been split into many various TextBlocks and removed from the parent children collection.

clip_image061

 

4.       We can get a collection of TextBlocks that replace our original TextBlocks like this:

clip_image062

 

clip_image063

 

5.       And when we run the sample:

clip_image064

 

 

Wrapping a TextBlock

1.       Let's add a TextBlock to our page

 

clip_image065

 

clip_image066

 

2.       Now let's change this snuggly fitting TextBlock to have less width and more height (no breaklines were added mind you).

 

clip_image067

 

3.       The text will automatically be wrapped by the RTLExtender.

clip_image068

 

4.       We can set the TextBlock to TextWrapping.NoWrap and it will be handled by the normal Silverlight NoWrap engine:

clip_image069

 

clip_image070

 

 

5.       We can set TextWrapping.WrapWithOverflow and it will extend slightly beyond the bounds of the TextBlock.

clip_image071

 

clip_image072

 

Questions, follow-up and suggestions

Bugs

You will find bugs with this project.
Seriously, I'm not that smart I can rebuild both Hebrew & Arabic RTL and align-to-right support in 10 hours.

Please go to the project's codeplex page at http://www.codeplex.com/SilverlightRTL and Create a new Issue.
Write what error you received, add the appropriate Minimal & Relevant code.
If something isn't working as you expect it to, tell me what you expect and what actually happens.

Attach a print screen if possible.

image


Feature requests

Additionally, you might want additional features (having the RTLExtender set it's own Fonts and download them from the server comes to mind).

Same goes, open a new issue and I'll do my best.


Check for updates

This project will surely undergo constant changes in the first 30-60 days after publishing.
If you're using this project, please signup to our RSS feed so you get notices.
RSS feed can be found at:
http://www.codeplex.com/SilverlightRTL/Project/ProjectRss.aspx

 

Here are my personal details just in case you feel the codeplex page isn't sufficient:
Email:
J@JustinAngel.Net
Cell: +972 546 567789
Office: +972 3 9504364

I'm serious about this, don't hesitate to contact me.

 

 

Well, that's about it.

Justin-Josef Angel,

Senior .Net consultant, Microsoft C# MVP

Question from Silverlight forums: Custom Context menu and Mouse Right Click Event

Question:

Is possible to create a context menu with Silverlight 1.1 and override or extend the currently context menu with Silverlight configuration?

 

Answer:

First let's explain the problem further. Silverlight doesn't have an event to catch a mouse right click. Here's the official list of Mouse events in Silverlight (from the SDK):

image 

And if we right click on a Silverlight application we'll get this normal context menu:

 image

There are occasions where we would need to use our own context menu and not the default silverlight one.

So yes, it's completely possible to change Silverlight's ContextMenu.
The solution isn't one native to Silverlight, though it can be implemented almost completely either in SL 1.1 or SL 1.0.

The main point of our solution is using the Javascript "ContextMenu" event the belongs to Silverlight host DOM element and creating our own implementation of it. That's how we created custom Context Menu using Javascript back in the good old HTML days.

With Internet Explorer we can sign-up for the event using this syntax:

    <div id="SilverlightControlHost" class="silverlightHost" oncontextmenu="RTLRightClickFix();" >

        <script type="text/javascript">

            createSilverlight();

        </script>

    </div>

With FireFox we'll need to use this Syntax:

if (window.addEventListener) {

    window.addEventListener('DOMContentLoaded', FirefoxLoad, true);

}

 

function FirefoxLoad() {

    document.getElementById('SilverlightControlHost').addEventListener('contextmenu', RTLRightClickFix, true);

}

 

Now, we've got the "RTLRightClickFix" method that'll get called on a mouse right click event!
We've basically just created Silverlight's missing "MouseRightClick" event.

 

Now that we've got control over the Right Click event we can show any "Menu" we'd like based on current mouse positions.

In SL 1.1 this is roughly the point we'll call a [ScriptableAttribute()] API and have it do most of the heavy lifting (showing a Context Menu Canvas based on current (X,Y) mouse positions).

 

The code for this solution and a live example can found at:
http://www.realtimesilverlight.com/RTLRightClickFix/RTLRightClickFix.aspx

 

Link:  http://silverlight.net/forums/p/5934/18126.aspx

Silverlight 1.0 Javascript Intellisense - minor updates (V1.1)

Based on your feature requests I'm releasing an updated version of the Silverlight Javascript Intellisense.
https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=intellisense&ReleaseId=6504

image

 

Changes from V1.0 to V1.1:

1. Smaller Javascript files. (roughly 50% in actual file size)

2. Strongly typed Attached properties

3. Enum support.

4. getHost() support

5. exposed the inner Xaml element.

 

 

Smaller Javascript files. (roughly 50% in actual file size)

You've asked for it - you got it.

file sizes for V1.0:
Intellisense.js - 1,275KB
Intellisense.compressed.js - 425KB

image 

file sizes for V1.1:
Intellisense.js - 613KB
Intellisense.compressed.js - 279KB
image

 

Strongly typed Attached properties

In V1.0 you had to have local copies of the DependencyProperty you want to change.

Let's say we want to move "someElement" 100 pixels to the top of the screen by decreasing it's Canvas.Top by 100.

image 

image

image

image

    var CanvasTop = new DependencyProperty("Canvas.Top");

    someElement.setValue(CanvasTop, someElement.getValue(CanvasTop) - 100);

This required you to remember and spell correctly the name of the Attached Properties.
In V1.1 There's static field like constructs you can use.

image

image 

someElement.setValue(Canvas.get_TopProperty(), someElement.getValue(Canvas.get_TopProperty()) - 100);

 

Enum support

In V1.0 you had to initialize all your Enum values and remember them.

Let's say we want to check if a TextBlock has an underline as TextDecorations and if so set it's decorations to none.

image

image

 

    var TextDecorationsUnderline = new TextDecorations("Underline");

    var TextDecorationsNone = new TextDecorations("None");

 

    if (myTextBlock.get_textDecorations().element == TextDecorationsUnderline.element)

        myTextBlock.set_textDecorations(TextDecorationsNone);

 

In V1.1 you can use Enus almost the same way you do in C#.

image

image

image

    if (TextDecorations.is_Underline(myTextBlock.get_textDecorations()))

        myTextBlock.set_textDecorations(TextDecorations.get_None()); 

 

getHost() Support

In V1.0 we had no getHost(), In V1.1 we have getHost with full Intellisense.

image

image

image

image

    someElement.getHost().get_content().set_fullScreen(true);

 

And we can even use createFromXaml with full intellisense.

image

image

    someElement.getHost().get_content().createFromXaml("<TextBlock xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" x:Name=\"tbx2\" />", false);

 

exposed the inner Xaml element

You might want, on occasion to use the actual XAML element that works behind the scenes. In V1.0 you had to use the ".element" extension which you didn't get Intellisense for.

In V1.1 you get Intellisense for this property on every class.

image

 

If you've got any more feature request - I'm open to suggestions.

 

Question from Tapuz .Net forum: Dividing operators are not what you thought

שאלה:

אני רוצה לחלק 5/3 ולקבל את הערך המלא כלומר גם מה שמאחורי הנקודה העשרונית אפשר אולי להראות לי איך?

 

תשובה:

בואו נראה איך נראית חלוקה רגילה של למשל 6 ו-3.

            int result = 6/3;

            Console.WriteLine(result);

image 

כצפוי, התשובה היא 2.

עכשיו בואו נשתמש באותה תבנית ונחלק 5 ב-3.

            int intResult = 5/3;

            Console.WriteLine(intResult);

image

רגע, מה? 5 חלקי 3 זה לא 1.
אני זוכר בבירור שחווה הגננת אמרה שזה יותר מתפוח אחד ופחות משני תפוחים.

אמרו בפורום להמיר את התוצאה ל-double (או float) ואז נקבל את התוצאה הנכונה.

            double doubleResult1 = 5/3;

            Console.WriteLine(doubleResult1);

image

זה לא עזר - עדיין קיבלנו 1.

עכשיו בואו ננסה להמיר את שתי האגפים שלנו ל-double. (גם התוצאה וגם התרגיל)

            double doubleResult2 = (double) 5/(double) 3;

            Console.WriteLine(doubleResult2);

image

מסתבר, שחלוקה של שני intים תמיד תחזיר int מעוגל כלפי מטה.

כלומר, גם אם לחלוקה יש שארית, לא נקבל אותה כחלק מהמספר, ובחלוקה של intים תמיד יש סטייה של עד כדי שלם אחד מהתוצאה האמיתית.
אבל בחלוקה של doubleים או כל טיפוס מספרי אחר שמסוגל להכיל Precision ו-Scale אחרי הנקודה העשרונית - כן נקבל את שארית החילוק.

עכשיו השאלה המעניינת היא למה זה?

מה מסתבר? הכל עניין של איזה טיפוסים ננסה לחלק.
אם ננסה לבצע תרגיל שאין לו נקודה עשרונית - נקבל תוצאה בלי נקודה עשרונית.
אם ננסה לבצע תרגיל עם נקודה עשרונית - נקבל תוצאה עם נקודה עשרונית.

נביט על מה כתוב ב-C# Language Spec על ההתנהגות הזו:
http://msdn2.microsoft.com/en-us/library/aa691373(vs.71).aspx

image

image

אז מסתבר שרק חלוקה של שני אגפים מאותו טיפוס תחזיר את הטיפוס הרלוונטי.

אבל מה באמת מעניין בזה?
שעבורנו שאנחנו רואים בעין 3\5 זה בדיוק אותו דבר כמו 3.0\5.0.
אנחנו רואים הבדל במספרים (בגלל הנקודה עשרונית), אבל הסימן חילוק הסלאש הימני נראה לנו בדיוק אותו דבר.

זה לא אותו סימן!
סלאש ימני של חילוק בין טיפוסים שונים הוא לא אותו אופרטור! זה קוד שונה לחלוטין שרץ מאחורי הקלעים.
זה שהסימן / נראה אותו דבר זה לא אומר שמדובר באותו אופרטור.

ביינתים, בזמן שאני כותב את התשובה הזו, אמרו בפורום שאפשר גם לחלק רק באגף אחד מאותו טיפוס ועדיין נקבל מספר עם נקודה עשרונית. למשל:

            double doubleResult3 = 5 / (double)3;

            Console.WriteLine(doubleResult3);

            double doubleResult4 = (double)5 / 3;

            Console.WriteLine(doubleResult4);

image

אז למה זה קורה אם אמרנו ששני האגפים צריכים להיות מהטיפוס וזה מה שכתוב בתיעוד?
כי רק אופרטור אחד יתאים לתיאור של חלוקה של double באיבר אחר (או עם איבר אחר) והאיבר השני (שבמקרה שלנו הוא Int32) יומר אוטומטית ל-double.

המסקנה שלי וה-Best Practice היא - שמחלקים שני Intים ממירים את שניהם ל-decimal ומחזירים את התוצאה ל-decimal.
(אישית אני מעדיף לעבוד רק אם Int32 ו-decimal כטיפוסים מספריים, אבל זאת העדפה אישית)

קישור: http://www.tapuz.co.il/tapuzforum/main/Viewmsg.asp?forum=831&msgid=105840781