2010-12-29 12 views
0

I別のusercontrolによって、指定されたValuePropertyを介して更新されているusercontrolがある(下記のコードWindow.XAMLバインディングを参照)。他のusercontrolのプロパティが更新されると、値バインディングを介してTextBoxバインドキーボードで直接入力するときに失われる

しかし、私はusercontrolsテキストボックスに直接入力して、もう一度私の他のユーザーコントロールを使用してください。テキストボックスは決して再び更新されません。私のTextBox UserControlのValuePropertyが上書きされたようです。 TextBoxに直接入力したときに、Text = {Binding ...}が失われて上書きされたと仮定しています。

//Window.XAML 
<veraControls:veraCommandPanel Name="commandCTRL" Value="{Binding ElementName=MyKeyPad, Path=Value}" HorizontalAlignment="Right" Width="360.057" Margin="0,266,-92.834,0" FontSize="42" FontFamily="lcdD" Foreground="LimeGreen" Height="54.901" VerticalAlignment="Top" /> 

//Here is my userControl 
<UserControl x:Name="PART_command" x:Class="Vera.WPFControls.veraCommandPanel" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Height="Auto" Width="300" 
xmlns:local="clr-namespace:Vera.WPFControls"> 
<StackPanel> 
    <StackPanel.Resources> 
     <Style x:Name="PART_veraCommand" TargetType="{x:Type local:veraCommandPanel}"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type local:veraCommandPanel}"> 
         <Border Background="{TemplateBinding Background}" 
         BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}"> 
         </Border> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </StackPanel.Resources> 
    <TextBox Height="55" Name="PART_txtCommand" Text="{Binding ElementName=PART_command, Path=Value}" VerticalAlignment="Top" /> 
</StackPanel> 

//TextBox UserControl's Code Behind 
namespace Vera.WPFControls 
{ 
/// <summary> 
/// Interaction logic for veraCommandPanel.xaml 
/// </summary> 
public partial class veraCommandPanel : UserControl, INotifyPropertyChanged 
{ 

    public veraCommandPanel() 
    { 
     InitializeComponent(); 
     this.DataContext = this; 
    } 


    public event PropertyChangedEventHandler PropertyChanged; 
    protected void NotifyPropertyChanged(String info) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(info)); 
     } 
    } 

    public static DependencyProperty ValueProperty = 
      DependencyProperty.Register("Value", typeof(string), typeof(veraCommandPanel)); 

    //, new UIPropertyMetadata(false, new PropertyChangedCallback(PropChanged))); 

    public string Value 
    { 
     get 
     { 
      return (string)GetValue(ValueProperty); 
     } 
     set 
     { 
      SetValue(ValueProperty, value); 

    } 

} 

}

答えて

1

結合TwoWayを試してみて、このように:

Text="{Binding ElementName=PART_command, Path=Value, Mode=TwoWay}" 
+0

[OK]を私は、私はすでにこれを試みていると思いますが、再試行します。私が知りたいのは、私が間違っていることや、バインディングを上書きしないようにすべきでないことです。私は結果をあなたに知らせます。ありがとう – agentpx

+0

それはまだ仕事をしなかった、私のシナリオは、最初のusercontrolのテキストボックスからボタンをクリックするとuserControlは私の最初のusercontrolの値が更新されます。もう動作しません。 – agentpx

+0

うわーそれは働いた。しかし、今回は私の最初のコントロールにMode = TwoWayを使用しました。私のテキストボックスに直接入力するときUserControl私の最初のコントロールの値はTwoWayを使用して更新されていないので、それも更新されます。ありがとう、非常にたくさんのジェイ。私はあなたに投票した! – agentpx

関連する問題