[英]How to create custom controls using generic.xaml in Silverlight 5 without using WPF?
我想使用generic.xaml創建自定義控件數據網格。我已經使用Silverlight 5中的用戶控件模板創建了自定義控件。我沒有使用WPF。 如何使用generic.xaml創建?
您所描述的在Silverlight中稱為Templated Control
。
您必須提供三件事:
ControlTemplate
的默認Style
generic.xaml
中包含默認Style
的條目 示例:MyFeeblefezer.cs
public class MyFeeblefezer : Control
{
public MyFeeblefezer() { DefaultStyleKey = typeof(MyFeeblefezer); }
}
和MyFeeblefezer.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="MyFeeblefezer">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MyFeeblefezer">
<Grid>
<!-- here goes your visible control UI parts -->
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
和主題/generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyFeebleProject;Component/MyFeeblefezer.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.