1.wpf中有兩類模板,控件模板controltemplate和datatemplate都派生自Frameworktemplate。
總共有三大模板 ControlTemplate,ItemsPanelTemplate,DataTemplate。
a. ControlTemplate 主要用途是更改控件的外觀。它有兩個重要屬性:VisualTree(視覺樹)內容屬性和Triggers觸發器,對於觸發器可以不用過多考慮,觸發器可有可無。VisualTree就是呈現我們所畫的控件。Triggers可以對我們的視覺樹上的元素進行一些變化。
b. ItemsPanelTemplate 是個特殊的空間模板,主要用來標明多條目控件如何顯示它所包含的多項數據。也可以說是指定用於項的額布局的面板。多用於多個內容控件的目標。多為Panel屬性或者Panel結尾的屬性。
c. DataTemplate 主要用於數據的呈現。也被稱為顯示綁定數據對象的模板。
2.數據綁定
WPF 里分三種:Binding,PriorityBinding,MultiBinding,這三種Binding的基類都是BindingBase,而BindingBase又繼承於MarkupExtension。
常見的使用Binding方法是:
1 針對於繼承於FrameworkElement控件。 SetBinding(DependencyProperty dp,String path),SetBinding(DependencyProperty dp,BindingBase binding),其中FrameworkElement中SetBinding只對DependencyProperty有效。
2 另一種是 BindingOperations.SetBinding(currentFolder,TextBlock.TextProperty,binding);
BindingOperations.SetBinding的原型是
public static BindingExpressionBase SetBinding(DependencyObject target,DependencyProperty dp,BindingBase binding)
3 清除Binding:
BindingOperations.ClearBinding(currentFolder,TextBlock.TextProperty);//刪除currentFolder上的TextBlock.TextProperty綁定
BindingOperations.ClearAllBindings(currentFolder);//刪除currentFolder上的所有綁定。
直接對Dependency Property賦值也可以解除binding,不過只對單向binding有效。
4.邏輯樹和視覺樹 視覺樹時對邏輯樹的擴展
邏輯樹是視覺樹的子集
WPF通過邏輯樹處理依賴屬性繼承和資源的問題,視覺樹來處理事件路由、渲染、資源定位等
邏輯樹可以認為是XAML所見的,而視覺樹包含了XAML元素內部的結構
5.屬性變更通知 IpropertyChanged和ObservableCollection<T>
a. INotifyPropertyChanged向客戶端發出某一屬性值更改的通知。
b. ObservableCollection<T>類,它是實現 INotifyCollectionChanged 接口的數據集合的內置實現。表示一個動態數據集合,在添加項、移除項或刷新整個列表時,此集合將提供通知
6.ResourceDictionary
提供了包含元素和WPF應用程序的其他元素使用的Wpf資源的一個哈希表/字典的實現,實現了應用程序的資源的共享
、、、、待解決的問題
7.wpf和winform的區別
路由事件 命令(Command)