【发布时间】:2011-07-29 08:46:57
【问题描述】:
我目前正在执行http://www.windowsphonegeek.com/articles/Creating-a-WP7-Custom-Control-in-7-Steps 的步骤?在为 WP7 做一个自定义控件。我已经在普通的 windows phone Portrait Page xaml 文件(结合一些控件)中创建了我的控件,我不确定如何将它转换为在 generic.xaml 文件中工作(作为 ResourceDictionary)。到目前为止,它没有工作。
我尝试使用 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>
请多多指教。 谢谢,
【问题讨论】:
-
假设您已完成本教程并且它可以工作(如果没有,请描述问题)您究竟想将什么转换为 generic.xaml?
标签: windows-phone-7 custom-controls expression-blend