Category Archives: Core .NET

C# core development of all types (desktop, Silverlight, ASP.NET, etc.)

WPF Brushes: Solid, Gradient, Image, and More!

WPF objects take a Brush instance (an abstract class) for foreground and background colours. What is a legitimate brush, exactly? Surprisingly, it can be a solid colour, or a gradient (linear or radial); it can even be an image, or something more complicated (a compound image of sorts). The MSDN page gives the best overview of brushes, visually. Continue reading

Posted in Core .NET, WPF | Tagged , | Leave a comment

WPF Gotcha: Mouse* Event With a Backgroundless StackPanel

WPF’s StackPanel mouse events (MouseDown, MouseLeftButtonDown, and MouseRightButtonDown) don’t seem to work, even when the StackPanel is visible. That is, until you add a background of some colour and transparency. Strangely, this causes the events to fire — even though it was visible before. Continue reading

Posted in Core .NET, WPF | Tagged , | 3 Comments

Populating Fields and CRUD in ASP.NET MVC

How do we get ASP.NET MVC to populate field values in a strongly-typed Edit view? The answer is surprisingly simple: specify the model instance! In your controller, create or otherwise generate the instance you want to edit, and pass it into the returned View instance; ASP.NET MVC will fill out fields for you. Continue reading

Posted in Core .NET, Web | Tagged , , , | Leave a comment

Limiting the Number of Results from LINQ

How can you limit the number of objects returned from a LINQ query, i.e. only request the first N objects (similar to MySQL’s LIMIT keyword)? The answer is via the Take(n) LINQ method; it pulls the first N rows specified. Continue reading

Posted in Core .NET, Silverlight, Web, Wndows Forms, WPF | Tagged , | Leave a comment

Adding Objects to a Window or Page via a StackPanel

You can’t directly (programmatically) add controls to a Window or a Page in WPF. So how do you add controls? Simply add a StackPanel component, and add controls via the someStackPanel.Children.Add(someObject). Similarly, you can iterate to find controls from it. Continue reading

Posted in Core .NET, WPF | Tagged , | Leave a comment

UserControl/Page Navigation Architecture in WPF

How can you set up a WPF navigation with UserControl objects? We detail one design/architecture (for a small game): using UserControl (or Page) as a base class; creating a single Frame that switches content so change screens; and a navigation controller to encapsulate switching from control to control. Continue reading

Posted in Core .NET, WPF | Tagged , | 2 Comments

Unit Testing and Code-Coverage in Silverlight

You can run unit-testing and code-coverage on Silverlight applications (NUnit, PartCover, et all) with a bit of foresight and reorganization of your code. You can test core logic and classes, albeit not Silverlight-specific code. I show you how. Continue reading

Posted in Core .NET, Silverlight, Tools | Tagged , , , | 1 Comment

Optimization 101

How do you optimize your application? Should you? When? How? We go over the basics, with six “rules” that you can follow to help you effectively improve your application performance. Continue reading

Posted in Core .NET, Silverlight, Uncategorized, Web, Wndows Forms | Tagged , , , | 1 Comment

Tools Update: Read Embedded Text Files in Silverlight

Tools now includes a EmbeddedResourceFileReader class that allows you to read the contents of text files at runtime; this is exciting for Silverlight development, where you may have lots of data you want to dump into a file and read at runtime. Well, now you can! Continue reading

Posted in Core .NET, Libraries, Silverlight, Wndows Forms | Tagged , , , | Leave a comment

The “using” Statement and IDisposable

The using statement allows you to create a block of text around an object (or multiple objects), that implements IDisposable, and to have the CLR automatically call Dispose on that object (or multiple objects). Continue reading

Posted in Core .NET, Silverlight, Web, Wndows Forms | Tagged , , , | 4 Comments