問題:為了方便資源的復用,我們通常會把資源單獨抽取為乙個資源檔案,供其他檔案引用。而使用者自定義控制項usercontrol中經常需要引入多個資源檔案。而在xaml中由於標籤usercontrol.resources內僅可以包含乙個content子元素。
所以為了給usercontrol引入多個資源,xaml中應該這麼寫:
<usercontrol
x:class
="homedecorationpsd.presentation.views.uiwindow"
xmlns
=""xmlns:x
=""xmlns:mc
=""xmlns:d
=""xmlns:local
="clr-namespace:homedecorationpsd.presentation.views"
mc:ignorable
="d"
xmlns:system
="clr-namespace:system;assembly=mscorlib"
>
<
usercontrol.resources
>
<
resourcedictionary
>
<
system:double
x:key
="tabitemwidth"
>80
system:double
>
<
resourcedictionary.mergeddictionaries
>
<
resourcedictionary
source
="/presentation/resources/colorresources.xaml"
>
resourcedictionary
>
resourcedictionary.mergeddictionaries
>
resourcedictionary
>
usercontrol.resources
>
usercontrol
>
參考:
<usercontrol.resources
>
<
resourcedictionary
>
<
resourcedictionary.mergeddictionaries
>
<
resourcedictionary
source
="viewresources.xaml"
/>
resourcedictionary.mergeddictionaries
>
<
controltemplate
x:key
="validationtemplate"
>
...
controltemplate
>
<
style
x:key
="textboxwitherror"
targettype
="">
...
style
>
...
resourcedictionary
>
usercontrol.resources
>
WPF 給UserControl引入多個資源
問題 為了方便資源的復用,我們通常會把資源單獨抽取為乙個資源檔案,供其他檔案引用。而使用者自定義控制項usercontrol中經常需要引入多個資源檔案。而在xaml中由於標籤usercontrol.resources內僅可以包含乙個content子元素。所以為了給usercontrol引入多個資源,...
wpf中usercontrol建立與引用
1.建立usercontrol 專案 建立專案型別為usercontrol的專案,編輯專案,生成解決方案,debug中即生成usercontrol.dll 2.引用usercontrol 在自己的wpf專案新增對上面生成的dll的引用 標籤中 新增xmlns mycontrol 自己的名字隨便 cl...
WPF給ListBoxItem新增事件
第一種 其實這個可以通過繫結父控制項的屬性來實現,給個demo 前台 後台 private void button click object sender,routedeventargs e btn.setbinding button.contentproperty,binding 第二種 list...