2008-11-06 11 views
1

J'ai un WPF très simple UserControl:WPF UserControl - ne peut pas sélectionner TextBox

<UserControl x:Class="dr.SitecoreCompare.WPF.ConnectionEntry" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
x:Name="connEntry" 
BorderBrush="Navy" BorderThickness="1" Margin="5,0,0,5" > 
<StackPanel Margin="0,10,0,0" > 
    <Label FontWeight="ExtraBold" Content="{Binding ElementName=connEntry, Path=Title}"></Label> 
    <Label Margin="0,5,0,0">Server:</Label> 
    <TextBox x:Name="txtServer" TabIndex="1" Text="{Binding Path=ServerName}" ></TextBox> 
    <Label>Database:</Label> 
    <TextBox x:Name="txtDatabase" TabIndex="2" Text="{Binding Path=DatabaseName}"></TextBox> 
</StackPanel> 

Ceci est utilisé deux fois dans la même fenêtre. Maintenant, je peux sélectionner le premier TextBox sur les deux instances de mon UserControl, mais le deuxième ("txtDatabase") zone de texte ne peut pas être sélectionné, ni en tabulant ou en cliquant sur. Pourquoi est-ce ? Suis-je en train de manquer quelque chose en ce qui concerne la création de WPF Usercontrols? Le nom de la base de données n'est pas en lecture seule, c'est une propriété simple.

EDIT: Le XAML pour la fenêtre UserControl est placé sur ressemble à ceci:

<Window x:Class="dr.SitecoreCompare.WPF.ProjectDialog" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:c="clr-namespace:dr.SitecoreCompare.WPF"  
    Title="Choose project" Height="280" Width="500" 
    WindowStartupLocation="CenterOwner" WindowStyle="SingleBorderWindow" HorizontalAlignment="Center" ShowInTaskbar="False" ShowActivated="True" ResizeMode="NoResize" VerticalContentAlignment="Top" VerticalAlignment="Center"> 
    <StackPanel> 
     <Label>Choose databases</Label> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition /> 
       <ColumnDefinition /> 
      </Grid.ColumnDefinitions> 
      <c:ConnectionEntry Grid.Column="0" x:Name="connMaster" Title="Master:" Padding="5" /> 
      <c:ConnectionEntry Grid.Column="1" x:Name="connSlave" Title="Slave:" Padding="5" /> 
     </Grid> 
     <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0" > 
      <Button x:Name="btnCancel" Click="btnCancel_Click">Cancel</Button> 
      <Button x:Name="btnOK" Click="btnOK_Click">OK</Button> 
     </StackPanel> 
    </StackPanel> 

</Window> 

Répondre

2

Essayez Mode = TwoWay dans votre liaison. J'ai vu cela où l'initialisation définit la valeur et le contrôle ne peut pas définir la valeur.

<TextBox x:Name="txtDatabase" TabIndex="2" Text="{Binding Path=DatabaseName, Mode=TwoWay}"></TextBox> 
0

Cela fonctionne dans XamlPad, donc je pense qu'il ya quelque chose en dehors du code affiché qui est l'origine du problème. DatabaseName est-il en lecture seule?

Questions connexes