2015年12月9日 星期三

Create Customer DependencyProperty in WPF

使用Dependency property流程:
1. 建立Dependency object, 熱鍵(propdp), 最後一個參數可選擇要對應的屬性,

也可以選擇用function pointer
 這樣在呼叫的地方就可以使用此屬性


Reference: http://www.codeproject.com/Articles/135913/WPF-Dependency-Property-Compatible-with-XAML-Bindi


Create thread for functions which are class members


You need to create a static method to use as the actual thread start function, and pass a pointer to the instance as the lpParameter argument to CreateThread. That will get passed to the static method, which can cast it to an object pointer and call through to the member function.



class MyClass
{
    static DWORD WINAPI StaticThreadStart(void* Param)
    {
        MyClass* This = (MyClass*) Param;
        return This->ThreadStart();
    }

    DWORD ThreadStart(void)
    {
        // Do stuff
    }

    void startMyThread()
    {
       DWORD ThreadID;
       CreateThread(NULL, 0, StaticThreadStart, (void*) this, 0, &ThreadID);
    }
};
reference: 
http://stackoverflow.com/questions/1372967/how-do-you-use-createthread-for-functions-which-are-class-members

2015年11月17日 星期二

WPF Binding方式

WPF中在做Binding的時候, 需要指定他真正要Binding的地方, 不然是找不到的.

譬如說:
在CS檔中先建立屬性


然後建立連結


得到的空的, 因為並沒有將binding的對象通知TextBox. 因此我們可以透過將Element name通知給MyProperty, 這樣他就可以知道要跟誰做Binding.

這樣就可以不透過DataContext來做Binding.

2015年3月30日 星期一

WPF自訂控制項

WPF自訂控制項


在設計自訂控制項之前,先談談控制項的類型,在WPF中控制項分為兩大類:
  • 使用者控制項(User Control):繼承自UserControl類別,由現有的控制項組成,開發時工具提供UI設計畫面。
  • 自訂控制項(Custom Control):繼承自Control或FrameworkElement類別,要自訂自己的UI與功能