My blog has moved!

Visit http://blog.adamroderick.com/ and update your bookmarks.

Friday, February 26, 2010

Adding Clipping to a Canvas

I’m going through Jianqiang’s series laying out Silverlight’s potential as a game-building platform, which I am pretty excited about.  Expression Studio—and Visual Studio—are way more intuitive than I remember a lot of the Flash tools being.  My small contribution to the first post is to add clipping to the canvas.  If we are going to be building a game, and if the canvas is the frame where the user interaction happens, then the objects should be contained in the canvas.  In the two shots below you see the before and after of the animation—the red block just moves to wherever you click the mouse:

 

1   2

 

The animation works fine—the problem is the red block spills out beyond the boundaries of the canvas.  This is the default behavior of Canvas, but is easy to change with clipping.  The following XAML, placed inside the Canvas XAML, hides objects as they move outside the clipping region:

<Canvas.Clip>
    <RectangleGeometry Rect="0,0 800,600" />
</Canvas.Clip>

Notice the Rectangle geometry is sized to the same size as the canvas.  The result is the appearance the the objects are actually “inside” the canvas:

 

1   3

Labels:

Monday, February 22, 2010

Slides from Presentation on SharePoint Social Features 2/18/2010

I gave a presentation to the Colorado SharePoint Users Group on Thursday 2/18/2010.  It was a run through of all the social networking and social content generation features of SharePoint Server 2010.  I then walked through how to use the profiles object model to programmatically access some of the features and data, and render the result in a Silverlight web part.

Here is a link to the video.

Here is a link to the slides—not much to them, though, most of the content was in the demo.

Labels: ,

Monday, February 1, 2010

Utility to Get Feature Scope in SPFeatureReceiver

During development, I might change my feature’s scope in the feature.xml definition.  To make sure this never bites me, I always check in my SPFeatureReceiver methods to make sure I am casting the feature’s parent to the right object.  If not, I throw an SPException so the error gets displayed to the browser window.  I find myself repeating this for every feature I write, so here is a snippet I use to keep it DRY.

    internal static class FeatureReceiverUtil
{
/// <summary>
/// Returns an object representing the scope of the feature, and throws an SPException
/// if the scope is unexpected
/// </summary>
/// <typeparam name="T">should be SPWeb, SPSite, SPWebApplication, or SPFarm</typeparam>
/// <param name="properties">the properties from the feature receiver event</param>
/// <returns></returns>
internal static T GetScope<T>(SPFeatureReceiverProperties properties) where T : class
{
var scope
= properties.Feature.Parent as T;
if (null == scope) throw new SPException(
string.Format(
"Feature {0} ({1}) expected to be at the {2} scope but was not",
properties.Definition.DisplayName,
properties.Definition.Id,
typeof(T).Name
));
return scope;
}
}

Usage is:



SPWeb web = FeatureReceiverUtil.GetScope<SPWeb>(properties);

Labels: