开发者

custom control (generic.xaml) for WP7

I am currently following the steps http://www.windowsphonegeek.com/articles/Creating-a-WP7-Custom-Control-in-7-Steps? in doing a custom control for WP7. I have created my control in a normal windows phone Portrait Page xaml file (combining some control), I am not sure how I can convert it to work in generic.xaml file (as ResourceDictionary). So far it didn't work.

I tried to use Expression Blend to do the converting but I am not sure how to do it.

Edit: I am posting my code, it is a box that displays dynamic time. I want also to add properties for providing the Date and another for the color of the box.

This is the code so far.

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-names开发者_JAVA百科pace: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>

Kindly Advise me. Thanks,


While you can move the style of the user control to a ResourceDictionary, why bother when you can have that and the template in the corresponding XAML for your UserControl?

Simple set the inside MyUserControl.xaml , along with the other properties you wish to change.

But the whole part about separating a style of a custom control to a ResourceDictionary , haven't a awful lot to do with UserControls. Perhaps you should tell us what's really wrong, instead of asking meta-questions.


I had the same problem when trying to create control following to link you give.
Solution is to add

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

into Application.Resources tag in App.xaml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜