首页 新闻 会员 周边 捐助

我做自定义控件的时候 老是读取不了Generic.xaml 的样式,谁能帮我

0
悬赏园豆:15 [已关闭问题]

类文件:

public class ImageButton:ContentControl
{
public ImageButton()
{
this.DefaultStyleKey=typeof(ImageButton);
}
}

 

Generic.xaml:

代码
<ResourceDictionary
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom
="clr-namespace:MyImageButton">

<Style TargetType="custom:ImageButton">
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="custom:ImageButton">
<Grid x:Name="RootElement">
<Rectangle x:Name="BodyElement" Width="200" Height="100" Fill="Lavender" Stroke="Purple" RadiusX="16" RadiusY="16" />
<TextBlock Text="Clsick Me" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>

 

 

测试页面:

代码
<navigation:Page xmlns:my="clr-namespace:MyImageButton;assembly=MyImageButton" x:Class="SilverlightDemo.ImageButton.TestPage"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable
="d"
xmlns:navigation
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth
="1024" d:DesignHeight="768"
Title
="TestPage Page">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="91" />
<RowDefinition Height="677" />
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center">自定义Imagebutton控件</TextBlock>
<my:ImageButton Grid.Row="1" Width="200" Height="200">
</my:ImageButton>

</Grid>
</navigation:Page>

 

 

 总是读取不了 样式 不知道是什么原因

问题补充: 我的版本是Silverlight 4.0 vs2010 发现好多教程都是2.0的 是不是新版本的做法改变了
Jeremy Ding的主页 Jeremy Ding | 初学一级 | 园豆:0
提问于:2010-05-13 15:29
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册