In application using WCF service, it is not uncommon to create partial classes on client side in order to add properties on objects retrieved by the service. Theses properties are needed by the client application (for interface for example) and they have no reason to present on server side.
For instance, a class name Product has following properties defined on server side : Price, Name, Stock and has the property IsVisible defined on client side in order to display or not the product on UI. Methods can also be defined in these partial classes.
Example :
[DataContract]
public class MyClass
{
[DataMember]
public string Label { get; set; }
}
Partial_MyClass.cs (client side) :
public partial class MyClass
{
public bool IsVisible { get; set; }
public void Display()
{
IsVisible = true;
}
}
In the Visual Studio 2010 default configuration (Just My Code enabled), breakpoints will not be hit in peviously created partial classes. When disabling “Just My Code” (Debug -> Options -> Enable Just My Code), breakpoints will be hit but StepOver (F10) and StepInto (F11) will not work.
This behavior is caused by DebuggerStepTroughAttribute attribute present in Reference.cs file in order to avoid Visual Studio debugging tools to go into this file (WCF proxy generated by Visual Studio or svcutil/slsvcutil).
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="MyClass", Namespace="http://schemas.datacontract.org/2004/07/MyApp.Client.Web")]
public partial class MyClass : object, System.ComponentModel.INotifyPropertyChanged {
private string LabelField;
[System.Runtime.Serialization.DataMemberAttribute()]
public string Label {
get {
return this.LabelField;
}
set {
if ((object.ReferenceEquals(this.LabelField, value) != true)) {
this.LabelField = value;
this.RaisePropertyChanged("Label");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
To easily debug, edit Reference.cs file (generated by Visual Studio) and remove[System.Diagnostics.DebuggerStepThroughAttribute()] attribute from classes you want to debug.

Note : Ask Visual Studio to “Show all files” in solution explorer and don’t forget to repeat this operation when updating your service reference.
Thanks Gaël Covain for his help.
Here we are, my 1st “real” Windows Phone has just been published to Marketplace. This application allows you to read Geek and Poke and xkcd comics.
This 1st version is very basic but it was a good occasion for me to learn more about this domain.
If you find a bug or have suggestions for next versions, don’t hesitate to contact me.
A XAML file can be unreadable when there are a lot of attributes in controls. Lines are often too long to be displayed on screen (horizontal scrollbar is required).
Visual Studio 2010 offers an option allowing us to put one attribute per line automatically to facilitate code reading.
So, when you have written your code, press Ctrl + K + D to format XAML.
To activate this option, go to Tools -> Options, then open Text Editor -> XAML -> Formatting and select Spacing.
Next, check “Position each attribute on a separate line“.
After that, your XAML looks like this :
In Silverlight, the mouse wheel works very well with every main browser (Internet Explorer, Firefox, Chrome, etc.) but not when Windowless is enabled. When this feature is enabled, NAPI based browsers like Chrome or Firefox don’t allow Silverlight to manage the mouse wheel. This article explains how to get the mouse wheel event using DOM.
This article is based on code published on Compiled Experience but I’ve added some modifications to consider elements inherited from ItemsControl.
To use this behavior easily in your application, we’re going to create a Silverlight “Behavior” which will be added to your ListBox, ComboBox, etc.
Code is separated into 2 parts :
“Helper” code
public class MouseWheelEventArgs : EventArgs
{
public Point Location { get; private set; } public double Delta { get; private set; }
public bool Handled { get; set; }
public MouseWheelEventArgs(double delta)
: this(delta, new Point())
{
}
public MouseWheelEventArgs(double delta, Point location)
{
Delta = delta;
Location = location;
}
}
public class MouseWheelHelper
{
private static Worker MouseWheelWorker;
private bool isMouseOver;
public MouseWheelHelper(UIElement element)
{
if (MouseWheelWorker == null)
MouseWheelWorker = new Worker();
MouseWheelWorker.Moved += HandleMouseWheel;
element.MouseEnter += HandleMouseEnter;
element.MouseLeave += HandleMouseLeave;
element.MouseMove += HandleMouseMove;
}
public event EventHandler<MouseWheelEventArgs> Moved;
private void HandleMouseWheel(object sender, MouseWheelEventArgs args)
{
if (isMouseOver)
Moved(this, args);
}
private void HandleMouseEnter(object sender, EventArgs e)
{
isMouseOver = true;
}
private void HandleMouseLeave(object sender, EventArgs e)
{
isMouseOver = false;
}
private void HandleMouseMove(object sender, EventArgs e)
{
isMouseOver = true;
}
private class Worker
{
public Worker()
{
if (!HtmlPage.IsEnabled)
return;
HtmlPage.Window.AttachEvent("DOMMouseScroll", HandleMouseWheel);
HtmlPage.Window.AttachEvent("onmousewheel", HandleMouseWheel);
HtmlPage.Document.AttachEvent("onmousewheel", HandleMouseWheel);
}
public event EventHandler<MouseWheelEventArgs> Moved;
private void HandleMouseWheel(object sender, HtmlEventArgs args)
{
double delta = 0;
var eventObj = args.EventObject;
if (eventObj.GetProperty("wheelDelta") != null)
{
delta = ((double)eventObj.GetProperty("wheelDelta")) / 120;
if (HtmlPage.Window.GetProperty("opera") != null)
delta = -delta;
}
else if (eventObj.GetProperty("detail") != null)
{
delta = -((double)eventObj.GetProperty("detail")) / 3;
if (HtmlPage.BrowserInformation.UserAgent.IndexOf("Macintosh") != -1)
delta = delta * 3;
}
if (delta == 0 || Moved == null)
return;
var wheelArgs = new MouseWheelEventArgs(delta);
Moved(this, wheelArgs);
if (wheelArgs.Handled)
args.PreventDefault();
}
}
}
To get this information, we get the JavaScript DOMMouseScroll event for Firefox and the onmousewheel event for Chrome and others. When the wheel is used, information is transmitted from JavaScript to Silverlight.
The following code is the Silverlight behavior, which will be applied to controls in XAML. In the original post, we can only use this behavior with a ScrollViewer, so it was impossible to use it with a TreeView for example. With my modifications, it can be applied on any UIElement.
But to get properties like VerticalOffset, HorizontalOffset or methods like ScrollToVerticalOffset and ScrollToHorizontalOffset, a ScrollViewer object is required. Thankfully, for controls inherited from ItemsControl (TreeView, ListBox, etc.) the Silverlight Toolkit provides an extension method : GetScrollHost() allowing us to retrieve their ScrollViewer objects.
Don’t forget to add a reference to the System.Windows.Controls.Toolkit DLL in your project.
public class MouseWheelScrollBehavior : Behavior<UIElement>
{
private MouseWheelHelper helper;
protected override void OnAttached()
{
base.OnAttached();
helper = new MouseWheelHelper(AssociatedObject);
helper.Moved += OnMouseWheelMoved;
}
private void OnMouseWheelMoved(object sender, MouseWheelEventArgs e)
{
ScrollViewer sv;
double verticalOffset;
double horizontalOffset;
if (AssociatedObject is ItemsControl)
{
ItemsControl tr = AssociatedObject as ItemsControl;
sv = tr.GetScrollHost();
}
else
{
sv = AssociatedObject as ScrollViewer;
}
if (sv != null)
{
verticalOffset = sv.VerticalOffset;
horizontalOffset = sv.VerticalOffset;
sv.ScrollToVerticalOffset(sv.VerticalOffset + (e.Delta * -10));
sv.ScrollToHorizontalOffset(sv.HorizontalOffset + (e.Delta * -10));
}
}
protected override void OnDetaching()
{
base.OnDetaching();
helper.Moved -= OnMouseWheelMoved;
}
}
When the “Behavior” is created, apply it to every Listbox, TreeView, ComboBox, etc. in your application like this :
<ListBox>
<i:Interaction.Behaviors>
<behaviors:MouseWheelScrollBehavior/>
</i:Interaction.Behaviors>
<!-- Code -->
</ListBox>
Where i represents System.Windows.Interactivity (don’t forget the reference) and behavior represents the “Behavior” namespace created above.
To do this tedious task, the best solution is to create a default template for these controls :
<Style TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer>
<i:Interaction.Behaviors>
<behaviors:MouseWheelScrollBehavior/>
</i:Interaction.Behaviors>
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
So this behavior is now applied to all ListBox controls.
The project used in this article is available here.
Today, I decided to open a new blog in english which a translation of some articles published in my french blog about .NET technologies and especially Silverlight, Windows Phone 7 and web.
So I’m sorry if I make english mistakes in my articles
Enjoy your reading.