New Custom user control and Styling : blank

Nov 21, 2011 at 2:48 PM

Hello,

I'm trying to wrote a custom user control that would perform some search operation... since it can have two different template based on wich kind of presentation we would present I've developed a custom usecontrol as :

 

public class SearchCustomerUC : UserControl
    {
        private Grid layoutRoot;

        public override void OnApplyTemplate()
        {

         //doesn't break here


            base.OnApplyTemplate();

        }



        public SearchCustomerUC()
            
        {
                 SearchCustomerUC.DefaultStyleKeyProperty.OverrideMetadata(typeof(SearchCustomerUC), new FrameworkPropertyMetadata(typeof(SearchCustomerUC)));

        }

        static void SearchCustomerUC_Loaded(object sender, RoutedEventArgs e)
        {
            SearchCustomerUC search = (SearchCustomerUC)sender;
        }

        public string SearchText
        {
            get
            {
                return base.GetValue(SearchTextProperty) as string;
            }

            set
            {
                base.SetValue(SearchTextProperty, value);
            }
        }

        public string Description
        {
            get
            {
                return base.GetValue(DescriptionProperty) as string;
            }

            set
            {
                base.SetValue(DescriptionProperty, value);
            }
        }

        public bool? ShowInline
        {
            get
            {
                return base.GetValue(ShowInlineProperty) as bool?;
            }

            set
            {
                base.SetValue(ShowInlineProperty, value);
            }
        }

        public static readonly DependencyProperty SearchTextProperty =
          DependencyProperty.Register("SearchText", typeof(string), typeof(SearchCustomerUC));

        public static readonly DependencyProperty DescriptionProperty =
       DependencyProperty.Register("Description", typeof(string), typeof(SearchCustomerUC));

        public static readonly DependencyProperty ShowInlineProperty =
     DependencyProperty.Register("ShowInline", typeof(bool?), typeof(SearchCustomerUC));

    }

and here's the Themes\generic.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DOME;assembly=DOME">

       <Style TargetType="local:SearchCustomerUC" >
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate >
                    <Grid x:Name="LayoutRoot" Background="Plum" Width="500" Height="500">
                        <TextBox x:Name="textBox" Text="{Binding SearchText,Mode=TwoWay}" HorizontalAlignment="Left" Margin="26.46,32,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="216" Height="20"/>
                        <TextBlock x:Name="textBlock" Margin="256,32,117.54,0" TextWrapping="Wrap" Text="TextBlock" Background="Aqua" VerticalAlignment="Top" Height="20"/>
                        <Button x:Name="button" Content="Button" Margin="0,32,53.54,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="59"/>
                        <Border HorizontalAlignment="Right" Height="48" Margin="0,16,45.54,0" VerticalAlignment="Top" Width="578.46">
                            <StackPanel>
                                <StackPanel HorizontalAlignment="Right" Height="8" Width="0"/>
                            </StackPanel>
                        </Border>
                        <TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Height="16" Margin="16,8,0,0" TextWrapping="Wrap" Text="NDG/Intestazione" VerticalAlignment="Top" Width="96"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>

Am I missing something since I'm not able to see the usercontrol?

Thanks

Nov 22, 2011 at 9:35 PM

Looks like you're missing a TargetType on your ControlTemplate.

Nov 23, 2011 at 8:42 AM

should it also point to

TargetType="local:SearchCustomerUC" ?