2011-03-19 4 views
2

J'essaie de créer un contrôle de zone de texte personnalisé pour mon application WP7. Fondamentalement, je veux qu'il ait une fonction GotFocus et je voudrais être en mesure de le faire ont un certain nombre InputScopewp7: Contrôle personnalisé avec fonctions

J'utilise les ressources suivantes que ma base pour essayer de créer une zone de texte contrôle personnalisé:

Je peux obtenir la zone de texte à afficher dans mon application, mais je ne peux pas l'appel GotFocus à travailler sans avoir la fonction dans l'application (qui contrecarre le but).

La fonction GotFocus que j'appellerais normalement est également dans la classe de la génériqueTextbox. Comment j'appellerais le GotFocus et l'InputScope?

Le ResourceDictionary est le suivant:

<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:wp7CustomControlsLibrary"> 
    <Style TargetType="local:genericTextbox"> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> 
     <Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/> 
     <Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/> 
     <Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/> 
     <Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/> 
     <Setter Property="SelectionForeground" Value="{StaticResource PhoneTextBoxSelectionForegroundBrush}"/> 
     <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> 
     <Setter Property="Padding" Value="2"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="local:genericTextbox"> 
        <Grid Background="Transparent"> 
         <Border x:Name="EnabledBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="{StaticResource PhoneTouchTargetOverhang}"> 
          <Grid> 
           <ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch"/> 
          </Grid> 
         </Border> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

Répondre

1

I figured it out. Fondamentalement, j'ai dû ajouter ce qui suit au code derrière:

public override void OnApplyTemplate() 
    { 
     base.OnApplyTemplate(); 
     GotFocus +=new RoutedEventHandler(OnTextboxInputWordGotFocus); 

     this.InputScope = new System.Windows.Input.InputScope() 
     { 
      Names = { new InputScopeName() { NameValue = InputScopeNameValue.Number } } 
     }; 

    } 

Cela fonctionne comme je veux maintenant. Cependant, s'il y a de «meilleurs moyens» de le faire, je suis ouvert aux suggestions.

Merci!

Questions connexes