Showing posts with label Karim. Show all posts
Showing posts with label Karim. Show all posts

Wednesday, July 1, 2009

Silverlight MVP

about a year ago I was at TechEd 08 taking to a friend (Peter) and he asked me if I was an MVP and I had no idea what that was. Granted I had heard it but never spent enough time to put 2 and 2 together. Well over the course of the next year and half or so I did find my self more involved in user groups such as the Seattle Designer Developer Interaction Group and Silverlight Insiders Group and of course I was already going to all the cool events such as MIX. I got a tweet from Suzanne at Microsoft Tuesday evening that I had been awarded Silverlight MVP.

For many years now I have been scoofing at things like MCP etc as I found that certifications like this tend to be something students do but the guys that are really good were the ones that can whip out the stack of experience and code. So for the most part I didn't care about that. I guess why I'm so proud of the MVP award is that it is not something you can just take a test. It is awarded based on contribution to the community and on the work you do professionally. As I understand it other MVPs or MS employees are the only ones that can nominate you and to be recognized like that for the hard work (albeit doing things like Silverlight Simon I have a hard time calling 'work') by others that are generally smarter then me is something I'm really proud of. Of all the silly certifications from school or other industry related stuff the only one that matters to me is Silverlight MVP.

In any case here is my MVP Profile:

https://mvp.support.microsoft.com/profile/David.Kelley

Friday, June 26, 2009

MediaElement for Sound effects

In doing Silverlight Simon and friends and then trying to port the uber tile from Silverlight to WPF I found that for doing quick short sounds there was a limit in Silverlight and WPF to the preformance and bahavior you can expect. WPF's 'MediaElement' is just horride but even in Silverlight if I try to use the same media element to play 2 short 2 second clips with in 1 second you will get issues. I must say though the Silverlight team has done a bang up job on the media element. It is orders of magnitude better then the one in WPF.

As part of pulling bits out of the crossfader codebase to post on codeplex I built a new 'MediaElement' class (see http://Crossfader.codeplex.com/) that solves this problem with sound in Silverlight and WPF and makes my life just that much easier for building composite apps.

So Karim suggested something called channel support to solve this and in this control I implemented it. Basically what happens is that the usercontrol called 'MediaElement' creates a collection of MediaElements that it then can have events and flags for for tracking state and each of these is a 'channel'. When you call SetSource the control looks for the first available channel to assigns the source. this actually creates like a quing mechinism that allows me to rapidly play sound effects without loosing one or having to wait for the control to have its mediaelement in a ready state and I don't need to have an army of media elements.

Also in WPF and Silverlight the usage can be then the same where I call SetSource and pass in a local uri path like this:


Target1.SetSource(http://localhost:52076/tone3.mp3);

or

Target1.SetSource("tone3.mp3");

in this case make sure the item is a local 'resource' in the xap with the control. In any case check out on the crossfader codeplex project or the HackingSilverlight library.

Thursday, June 4, 2009

Setter Value Binding Helper

A great little Hack in Silverlight, kind of technical stuff for the beginner but a good thing to have down in your professional developer toolbox.

http://blogs.msdn.com/delay/archive/2009/05/07/one-more-platform-difference-more-or-less-tamed-settervaluebindinghelper-makes-silverlight-setters-better.aspx

thanks to karim for this link.

More Simon the Saga

in this latest chapter of simon I have been trying to get 'Simon' to run in a scatterview control on surface to be more 'Surfacy'? [Sir - fa - see]? (new word?) In any case the code from Silverlight Simon to Surface Simon had to have even more hacks... Finally had to convert all the game pads to buttons, hack out the control template and create new event handlers for all 4 buttons. but alas Surface Simon is not available for Download off of codeplex at: http://Simon.codeplex.com/

Also to get around the sound issue with WPF... which I must say the fact that the media element is so lame in WPF as opposed to Silverlight is very very sad. Anyway I changed the PlaySound method of Simon to look like this:


#if Silverlight
Uri MediaItem = new Uri(SoundFile, UriKind.RelativeOrAbsolute);
SimonSounds.Source = MediaItem;
SimonSounds.AutoPlay = true;
SimonSounds.Play();
#else
MediaPlayer mplayer = new MediaPlayer();
mplayer.Open(new Uri(SoundFile, UriKind.Relative));
mplayer.Play();
#endif

you'll note the use of precompiler specifiers and that we are not using the Xaml based media element in the WPF/Surface versions any more...

Sunday, May 17, 2009

Xaml WCF Binding Type

Just kidding... as of late I am not aware of such a think however, it could be done. I was pooring over the great project in outer darkness I'm working on and Karim sitting near by was talking about using Xaml as Clr Object markup and Xaml Reader. In joking about it came up to use Xaml as and WCF binding type. Eventually we got to a more serouse topic about the limitations of WCF support in Silverlight event Silverlight 3. In any case John Papa's book on data driven services with Silverlight 2 is probably the best resource on the topic as of late and John did quick post recently on Silverlight 3 and bindings supporting in Silverlight 3 which includes binary support which would be made in some 'Xaml' hack :)

http://johnpapa.net/silverlight/wcf-binary-bindings-in-silverlight-3/

Wednesday, October 1, 2008

Silverlight 3D...

Karim sent me this link to this guy that did this '3d' silverlight solution. here is only a video but its pretty slick...

http://www.innoveware.com/

speacking of 3d silverlight there are also a couple of related projects on codeplex. Faisal Khan a friend sent me a mini me version that does a puesdo 3d layout based on x, y and z. I'm playin with a wrapper class that will allow more complicated 3d effects but his View3D panel works well and we'll drop it into the hackingsilverlight library for our own little mini me 3d engine for Silverlight that not only for the book but we will use it for the project george that I'll talk about at some later point after the book is finished, completely.

Thursday, August 21, 2008

Tuesday, August 19, 2008

IntelliSense for Expression Blend

check out Stefans post on 'hacking' blend. He wrote intellisense :)

http://blogs.telerik.com/StefanDobrev/Posts/08-08-04/IntelliSense_for_Expression_Blend.aspx

alittle bit of Kaxaml and mix in some Addin and ICodeEditor goes a long way :)

Friday, August 1, 2008

Wednesday, July 23, 2008

Hacking Expression Blend

Adding Features and Plug-ins to Blend


To start with you will need to make sure Expression Blend is installed and we get a copy of the ‘Microsoft.Expression.Framework.dll’ which will be installed in the Microsoft Expression directory under program files or other location depending on how you installed. If you can’t find this directory you can do a global search on ‘Microsoft.Expression.Framework.dll’ and you will find it.


Now that you have the DLL we can now open Visual Studio and start a new project. For really hacking into Expression Blend so that our application or whatever it is you want to do in Blend we should use the WPF Custom Control Library project type found under the language of your choice (C# or VB.NET) and then under windows. Once the project is created drag a copy of the dll into the solution explorer and into the project. This DLL contains all the base class types used to wiring things into the Expression Blend infrastructure. Granted much of the stuff in Blend is sealed or closed there is enough available to us to be able to hack. You might ask since at the time of writing this the info was not publicly available or even privately available and since I’m not a Microsoftee how did I find this out…? Wel I want to thank a friend named Karim Hernandez with a little too much time on his hands and a nifty tool called ‘Reflector’ for finding this stuff out.


.NET Reflection and Probing the guts of .NET Binaries


A bit of topic but a critical skill to really pushing the limits to .NET programming in general is the albity to look into DLL’s and see what is there even if you are not provided documentation about what is in a binary. With .NET we have a built in technology for reading binary .NET content called reflection and through tools like ‘Reflector’ you can probe into the guts of things even if your not supposed to and using reflection or just referencing the DLL’s you can create instances of class’s you might not supposed to have. Case in point is sinsce Blend is a WPF application its DLL’s and binaries can be ‘probed’ and explored as it were and since this infrastructure is or will be probably available to control vendors at some point for extending blend we can go ahead and use it. However that being the case they could change and since we all know about .NET Reflection we can work it out.


Back to hacking Blend…


Now we need to create a reference to Blends Framework DLL so we can start implementing things we might want. Right click on our controls project and select ‘Add Reference’. You will need to select the Browse tab from the Reference dialog and then find the DLL we added to our project. Select it and click ‘OK’ which will not allow us to include references in the specific class’s. Start by renaming our ‘CustomControl1’ class to OurFirstBlendHack more for our own entertainment value. Visual Studio will ask about renaming all the references and you want to select yes so that the name change is clean and won’t break anything. Then at the top of the source fille add this line at the top:


using Microsoft.Expression.Framework.AddIn;
using Microsoft.Expression.Framework;


Now we have the ablity to start using the DLL content in our OWN classes how ever we want. We will start by making our Class a Blend Adding and in heriting from IaddIn which is the base class for Blends Framwork if you want to extend the functionality or add your own stuff into blend or whatever cool Silverlight tools you can think of. A real live use might be to integrate group Xaml/Silverlight editing tools like KaXaml or adding your own code formating or even a custom Silverlight control library. But first we need to make our first class definition look like this:


public class OurFirstBlendHack : IAddIn


And then add the detail meta data for Blend right before this first line like this:


[AddInDescription("OurFirstBlendHack", AddInCategory.Tool)]


With that we need to add a several methods to start mucking around with to deal with the StartUp event, Intialization, Dispose and the ShuttingDown event in Blend. The three events actually look like this:

public void Initialize(IApplicationService applicationService) { }

public void StartupComplete() { }

public void ShuttingDown() { }

public void Dispose() { }


Before we compile we also need also to remove the constructor or at least remove the line of code for setting the defaultKeySetter which will normally be added ‘for’ you as Visual Studio assumed this was inheriting from Control by default. Once the constructor is dealt with we then compile. Do this to make sure you have not made any errors but currently the class is valid but is not going todo anything. Our next step is to add some code and run it from Blend to see if we can make our ‘Addin’ work. Add the following line to our method StartupComplete.


MessageBox.Show("Blend is Hacked!");


Again this is not going todo anything until we run it from blend but if it is done then we should get a default windows dialog poping up with the label from our code. Todo this we need to make sure our code is compiled and then we need to open a command prompt test our code. Copy the DLL into the Blend directory and use the following at the command prompt:


Blend.exe /addin:HackingBlend.dll


This will start blend and blend will run the class we created and you will get the popup dialog ‘Blend is Hacked!’. If you really want to-do something as part of blend though, we might want to start with a menu. A custom menu in Blend is straight forward enough, but first let us build out what the menu will do. We can start this by making a command class. First create a new class in our project called HackCmd. Add the following includes at the top:

using Microsoft.Expression.Framework.AddIn;
using Microsoft.Expression.Framework;
using Microsoft.Expression.Framework.Commands;


Then we need to make the class inherit from the base command object like this:


internal class HackCmd : Command


To make the object actually do something we still need to add internal code to the class as well as the required API needs implemented to support usage. The main thing we want to implement then is the method Execute and our constructor. In this case this should look like the following Listing:

private IApplicationService _ApplicationService;

public HackCmd(IApplicationService ApplicationService)
{
_ ApplicationService = ApplicationService;
}

public override void Execute() { }


Now that we can Hack Blend lets close out the chapter summarizing what we learned. Next for testing lets add a line to Execute to actually do something like this:


MessageBox.Show("Blend is Hacked even more!");


This gives us something to call from our menu and from here we can open additional dialogs or WPF windows etc to perform whatever task we want to do. Remember then if you want a window for example to open you put it into the execute method of your command objects. To really make the menu work we still need one other class and that is a command target that receives menu events and routes them to the command class. Add a new class to your project called HackCmdTarget and add the additional using statements to top that you added to the HackCmd class. Then make sure we have our inheritance correct by making the class declaration look like:


internal class HackCmdTarget : CommandTarget


Now we need to fill out the guts of the class. In the case of the Target we are only adding a constructor and the references to the HackCmd class that we add to Blends command collection. The internal code then for our HackCmdTarget should be like the following listing:

internal static string HackCmdCommandName = "HackCmd_Command";

public HackCmdTarget(IApplicationService ApplicationService)
{
base.AddCommand(HackCmdTarget.HackCmdCommandName, new HackCmd(ApplicationService));
}


Now we can go back to the first class we created called OurFirstBlendHack and build out our Blend menu structure. Add the following line to add our command to blend when our class is loaded on Initialize to our class’s Initialize method:


ApplicationService.CommandService.AddTarget(new HackCmdTarget(ApplicationService));


Now Blend can see the target command and we can add a menu to call it. To create an instance of Blends menu we need to add a using statement to the top like this:


using Microsoft.Expression.Framework.UserInterface;


Then we can create an instance of the menu bar in blend and can add elements to the menu. Add the following line of code to the Initialization menu to create an instance of the menu like this:


ICommandBarMenu menu = ApplicationService.CommandBarService.CommandBars[0].Items.AddMenu("HackBlend", "HackBlend");


Now to add elements to our new menu we can call methods on our menu instance. In this case we can use ‘AddButton’ and ‘AddSeparator’ to build a little menu. Use these lines of code to add our elements and route our commands:


menu.Items.AddButton(HackCmdTarget.HackCmdCommandName, "alert us");
menu.Items.AddSeparator();
menu.Items.AddButton(HackCmdTarget.HackCmdCommandName, "another alert");


Now we can compile and then copy our DLL to the blend folder and run from the console the following line:


Blend.exe /addin:HackingBlend.dll


This will run Blend and run our little class in the context of Blend including our menu. If you try this you can see we have ‘hacked’ Blend or at least used its plug in framework to allow us to ‘extend’ Blend to do new and better stuff with our Silverlight Xaml. Now let us summarize what we have learned.

Also check out Karim's blog and post on topic at: http://dragonshed.wordpress.com/2008/07/11/blend-addin/

Tuesday, January 29, 2008

Silverlight Applications Taking All the Available Realestate

Karim sent me this. It is a simple way make sure you Silverlight Application uses all the available realestate using just CSS:


/* hide from ie on mac \*/
html
{
height: 100%;
overflow: hidden;
}
.silverlightHost
{
height: 100%;
width: 100%;
}
/* end hide */

body
{
height: 100%;
margin-left: 1px;
margin-top: 1px;
margin-right: 0px;
margin-bottom: 0px;
padding: 0;
}


Now there are other ways todo this such as from the HTML body onload event and also the resize event on the window together or other programatic ways but this is just nice and simple and I say keep it simple unless you have to.

Thursday, November 8, 2007

VS TFS Hack...

Here is a little hack for Visual Studio that is useful if you are using Team Foundation Server (TFS) and Visual Studio 8 and dont' want VS to auto connect...

I got this from another friend (WPF guy) Karim H.

"Below is a registry setting which will prevent VS from attempting to automatically connect to TFS on launch. Instead you will need to hit the refresh button in Source Control Explorer, or open a solution with bindings to TFS."

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\8.0\TeamFoundation]
"AutoLoadServer"=dword:00000000