所以我喜歡自定義控件的外觀可以在generic.xaml中重新定義的事實,所以我想創建一個。但我的問題是,您最初如何設計(使用設計師)自定義控件的外觀?與用戶控件不同,它沒有附加的xaml/designer窗口。那麼必須在代碼中設計它們嗎?WPF:如何在設計器中定義自定義控件的外觀?
1
A
回答
2
您創建一個ResourceDictionary
XAML
文件,在其中您控制定義CustomTemplate
/Style
,然後合併所有這些字典在Generic.xaml
字典。
例如,定義一個控件的樣式:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="RootElement" >
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
而在你Generic.xaml
:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyButtonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
的結果應該是Button
類型的控件現在指定的樣式呈現,即使在IDE設計師。
+0
這不會回答我的問題 – foreyez 2011-02-10 17:02:15
相關問題
- 1. 自定義控件外觀
- 2. WPF自定義控件 - 你如何測試自定義控件?
- 3. Android - 自定義微調控件外觀
- 4. 如何自定義Win32中的選項卡控件的外觀?
- 5. 如何在設計器中禁用編輯自定義控件
- 6. 如何在設計器中更新自定義控件?
- 7. 如何在WPF中自定義組合框按鈕外觀
- 8. 自定義控件不會在設計
- 9. WPF自定義NavigationUI控件
- 10. WPF和自定義控件
- 11. WPF自定義控件TemplateBinding
- 12. WPF:自定義控件
- 13. Wpf自定義控件
- 14. 自定義WPF控件
- 15. 如何實現自定義WPF控件
- 16. 如何自定義UISearchBar的外觀
- 17. 如何自定義asp.net DropDownList的外觀?
- 18. 自定義設計控制器
- 19. WPF:電位器自定義控件
- 20. 如何在自定義列表視圖樣式中自定義GridViewHeaderRowPresenter的外觀?
- 21. 如何在自定義控件中啓用設計支持?
- 22. 如何在android中設計自定義聊天控件?
- 23. 自定義`sliderInput()`外觀
- 24. 自定義UISlider外觀
- 25. 自定義textfieldUI外觀
- 26. 如何自定義Apple App Store外觀?
- 27. WPF自定義控件設計的問題
- 28. 自定義控件設計時
- 29. WPF中的Winform自定義控件
- 30. 自定義Swing外觀和自定義組件?
Expression Blend爲您提供了一個設計界面... – 2011-02-10 16:57:56