WPF – add key short cut for windows

there is two ways to add wpf key short cut.

1
2
3
4
5
6
7
8
9
        this.KeyUp += MainWindow_KeyUp;
 
        private void MainWindow_KeyUp(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.D1)
            {
                MessageBox.Show("1 is press");
            }
        }

but for the most normal way to do is to wpf resource.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
    <Window.Resources>
        <RoutedUICommand x:Key="ClickCommand" Text="Text" />
    </Window.Resources>
    <Window.InputBindings>
        <KeyBinding Command="{Binding Path=button_Click}" 
                Key="O" 
                Modifiers="Control"/>
        <KeyBinding Key="C" Command="{StaticResource ClickCommand}" />
    </Window.InputBindings>
 
    <Window.CommandBindings>
        <CommandBinding Command="{StaticResource ClickCommand}" 
                    Executed="button_Click" />
    </Window.CommandBindings>
 
    <Grid>
        <Button x:Name="button1" Content="1" HorizontalAlignment="Left" Margin="101,140,0,0" VerticalAlignment="Top" Width="75" Click="button1_Click" Command="{StaticResource ClickCommand}"/>
        <Button x:Name="button" Content="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="181,140,0,0" Click="button_Click" Command="{StaticResource ClickCommand}"/>
    </Grid>
Posted in WPF | Comments Off on WPF – add key short cut for windows

xamarin debug android on device and release to apk

this example code could be find on following url
https://github.com/emacslisp/XNA2DGame/tree/dev/Android/PlatformReading

1. How to build apk from visual studio
<1> change build mode from ‘debug’ to ‘release’
<2> select project properties and change option on ‘Application’, ‘Android Manifest’, ‘Android Options’

Android_Setting1

2. How to debug android with xamarin C# code
debug on physical device is the best way to go, simulator is very slow.

choose device and press F5

PlatformReading_Android

Posted in Uncategorized | Comments Off on xamarin debug android on device and release to apk

MonoGame – Personal Project and step by step tutorial

XNA Framework continued to developed by MonoGame.

I migrated my xna game to MonoGame using OpenGL
https://github.com/emacslisp/XNA2DGame

for ‘dev’ is Game using MonoGame with visual studio 2015
in ‘master’ branch is XNA 4.0 using visual studio 2010.

ExtremePong

game_1

Posted in MonoGame | Comments Off on MonoGame – Personal Project and step by step tutorial

c# – NHibernate.MappingException: No persister for: XYZ

nhibernate

as screen dump show, build action of XYZ.hbm.xml should be ‘Embedded Resource’.

Posted in Uncategorized | Comments Off on c# – NHibernate.MappingException: No persister for: XYZ

autofac build

get source code via git clone https://github.com/autofac/Autofac

open then solution Autofac.sln and build.

However, if you look at Reference of Autofac.xproj, it has two References, one is .net 4.5 and another one is .net core 1.0.

the output dll will be two as well, in bin folder, you could see two folders with name of two versions, one dll is for .net 4.5, another one is for .net core 1.0. (very important).
autofac-output

if you add some code (for example, System.Diagnostics.Trace.WriteLine) only supported by .net 4.5, then you could build .net 4.5 dll only.

Posted in autofac | Comments Off on autofac build

.net core – source code analysis starting

.NET Core is a cross-platform free and open-source managed software framework similar to .NET Framework. It consists of CoreCLR, a complete cross-platform runtime implementation of CLR, the virtual machine that manages the execution of .NET programs.

the Major code is developed by C++.

dotnet/cli – for CLI tools and questions
dotnet/corefx – for API issues and questions
dotnet/coreclr – for runtime issues
nuget/home – for NuGet questions and issues
aspnet/home – for ASP.NET Core questions and issues.

It is open source. and developer could investigate deeply under to every detail of C# running environment.

Building corefx and coreclr are almost same.

Step 1: open visual studio 2015 x64 command
Step 2: set cmake to PATH (install cmake if system don’t have)
Step 3: run build.cmd command.

bulid-net_core_cil

Posted in .net core | Comments Off on .net core – source code analysis starting

Visual Studio 2015 with Update 2 Short cut changes

jumping between pair “#region #endregion” short cut is Ctrl+] originally.

However, Now in Visual studio 2015 jump between the pair are changed to Ctrl+Shift+Up/Down.

Ctrl+Shift+8 is not working any more, Ctrl+- has to be used.

I will update more short cut changed for VS2015 comparing to old version such VS2010

Posted in C# | Comments Off on Visual Studio 2015 with Update 2 Short cut changes

C# Reflection – set object enum property value

using C# Reflection can convert DataTable to Object easily.
However, it may be have some problems when converting enum which is special, we don’t know enum type and enum type should get from reflection.

Here is code sample for c# enum property covert.

1
2
3
4
5
6
7
8
var a =  new YourObject(); 
PropertyInfo propertyInfo = a.GetType().GetProperty(s);
if (propertyInfo.PropertyType.IsEnum)
  {
    propertyInfo.SetValue(a, Convert.ChangeType(Enum.Parse(propertyInfo.PropertyType, dr[index++].ToString()), propertyInfo.PropertyType), null);
  }
 else
    propertyInfo.SetValue(a, Convert.ChangeType(dr[index++].ToString(), propertyInfo.PropertyType), null);
Posted in C# | Comments Off on C# Reflection – set object enum property value

some tricky in ng-repeat update model in ionic

ng-repeat is to loop thought object list and auto generated html.

for example
in controller, we declare
$scope.workspaces.

Now $scope.workspaces = getDataFromDatabase();

1
2
3
<li class="workspace-object" ng-repeat="w in workspaces | filter:searchQuery" ng-click="selectWorkspace(w)">
    <a href="" class="workspace-link">{{w.name | titleCase }}</a>
</li>

It will not updated.

Make following change it will work.

1
2
$scope.work={}; //very important, declare object first.
$scope.work.workspaces = getDataFromDatabase(); //workspaces object should under work object.

change ng-repeat to be ng-repeat=”w in work.workspaces | filter:searchQuery”

Posted in Angular.js | Comments Off on some tricky in ng-repeat update model in ionic

Angular.js compile document to tree struction

the first step of angular.js is to compile document to element and childnode. this struction is similar with DOM.

module is key concept of angular.js. what is angular.js module.
A module is a collection of services, directives, controllers, filters, and configuration information.

for example:

1
var element = $compile('<p>{{total}}</p>')(scope);

it calls compile(…) function to find ‘ng-module’, ‘ng-controller’, something like ‘ng-xxxx’ and so on.

shortly, this steps compile html to tree, and Addmodule to lists, AddDirectives to directives lists.

this is critical steps of beginning. I will add more example and code to explain.

Posted in Angular.js | Comments Off on Angular.js compile document to tree struction