2011-07-29 45 views
0

我目前正在按照步骤http://www.windowsphonegeek.com/articles/Creating-a-WP7-Custom-Control-in-7-Steps?在为WP7进行自定义控制。我创建了我的控制在一个正常的Windows手机肖像页xaml文件(结合一些控制),我不知道如何将它转换为generic.xaml文件(作为ResourceDictionary)工作。到目前为止它没有工作。WP7的自定义控件(generic.xaml)

我试图使用Expression Blend做转换,但我不知道该怎么做。

编辑:我张贴我的代码,它是一个显示动态时间的框。我还想添加用于提供日期的属性以及用于框的颜色的属性。

这是迄今为止的代码。

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" 
xmlns:local="clr-namespace:CereTime"> 
    <!-- Check xmlns:local im case of error --> 
    <Style TargetType="local:CereT1"> 
     <!-- After specifing the custom properties in .cs file, implement them here --> 
     <Setter Property="Date" Value="{TemplateBinding Date}" /> <!-- Under check --> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="local:CereT1"> 
        <Canvas Background="YellowGreen" Width="100" Height="100" Name="DateBox" HorizontalAlignment="Left" VerticalAlignment="Top"> 
         <StackPanel Orientation="Vertical" Height="100" Width="100"> 
          <TextBlock Name="Month" Text="Month" Foreground="White" TextAlignment="Center" HorizontalAlignment="Center" FontSize="24" FontWeight="Bold" Margin="0,12,0,0" /> 
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,6,0,0"> 
           <TextBlock Name="Date" Text="0" VerticalAlignment="Bottom" Margin="0,0,5,0" FontSize="26.667"/> 
           <TextBlock Name="No_Name" Text="|" FontSize="26.667" /> 
           <TextBlock Name="Year" Text="Year" Margin="5,0,0,0" FontSize="26.667" /> 
          </StackPanel> 
         </StackPanel> 
        </Canvas> 
       </ControlTemplate>    
      </Setter.Value> 
     </Setter> 
    </Style> 
</ResourceDictionary> 

请给我建议。 谢谢,

+0

假设你已经完成了教程和它的工作原理(如果不是,请说明问题)究竟是你想转换为generic.xaml? –

回答

0

虽然你可以在风格的用户控件的移动到ResourceDictionary中,何苦时,你可以有一个和你的用户控件对应的XAML的模板?

简单地设置MyUserControl.xaml的内部,以及您希望更改的其他属性。

但是关于将自定义控件的样式分离为ResourceDictionary的全部内容与UserControls没有很大关系。也许你应该告诉我们什么是确实是错,而不是问元问题。

+0

这个(含糊不清)的问题是指自定义控件而不是用户控件。 –

0

我在试图创建控件后出现同样的问题,因为链接给出了。
解决方案是增加

<ResourceDictionary>  
    <ResourceDictionary.MergedDictionaries> 
     <ResourceDictionary Source="themes/generic.xaml"/> 
    </ResourceDictionary.MergedDictionaries> 
</ResourceDictionary> 

Application.Resources标签在App.xaml中