Category Archives: c#

Borders on WPF on 4K high resolution monitors

The issue is that when you view your WPF application on a normal 96 monitor everything looks fine, but once you view it on a high resolution monitor edges don’t seem to line up right everywhere and sometimes there are issues with the borders rendering and lining up correct.

The two key settings to try to fix this can be set at the page or window level and these are `UseLayoutRounding` and `SnapToDevicePixels`.


    UseLayoutRounding="True" SnapsToDevicePixels=True"

These features should work on both the classic .NET Framework and the new WPF running on .NET Core.

Reference

How to show a blank in a text box for an Integer value in ASP.Net MVC.

Question: In ASP.Net MVC5, how do I show a text box for a number in my ViewModel but have it show a blank when that value is 0?

Answer:

Let’s assume you have a ViewModel on the page that has an integer value that represents a month.  If the ViewModel is empty and that value is 0 (a month hasn’t been set yet)

@Html.TextBoxFor(x => x.Month, “{0:#.#}”)

In Dapper, how do I execute and use the results of a dynamic query?

Dapper is a framework that allows for SQL queries to be mapped into object models.  In most cases you will know the result of your query set and can map them accordingly but there are cases where you may not know what the return set includes

Here is an example of how you can make use of dynamics in C# to accomplish that.

var query = conn.Query<object>("select * from some_dynamic_resultset");
foreach(dynamic row in query)
{
    int id = row.Id;
    //...
}