2011-10-17 3 views
0

나는 listview가 있습니다. 다음과 같이 int를 설정했습니다. -listview의 텍스트 상자 - 소스 업데이트 및 탭에서 포커스 이동이 동시에 작동하지 않습니다.

<ListView KeyboardNavigation.TabNavigation="Local" SelectionMode="Extended"> 
<ListView.ItemContainerStyle> 
    <Style> 
    <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/> 
    </Style> 
</ListView.ItemContainerStyle> 

listview의 한 열에 TextBox가 있습니다.

내 텍스트 상자에 UpdateSourceTrigger = LostFocus 을 설정하면 목록보기를 통해 탭을 만들 수 없습니다 ... 대신 UpdateSourceTrigger = Explicit를 설정하면 탭이 작동하지만 소스가 업데이트되지 않습니다.

편집 아래

public class TextBoxBehavior 
    { 
     #region Attached Property EscapeClearsText 


     public static readonly DependencyProperty EscapeClearsTextProperty 
      = DependencyProperty.RegisterAttached("EscapeClearsText", typeof(bool), typeof(TextBoxBehavior), 
       new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnEscapeClearsTextChanged))); 


     private static void OnEscapeClearsTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
     { 
      if ((bool)e.NewValue) 
      { 
       var textBox = d as TextBox; 
       if (textBox != null) 
       { 
        textBox.KeyUp -= TextBoxKeyUp; 
        textBox.KeyUp += TextBoxKeyUp; 
       } 
      } 
     } 


     private static void TextBoxKeyUp(object sender, KeyEventArgs e) 
     { 
      if (e.Key == Key.Escape) 
      { 
       //((DataContext<string>)((TextBox)sender).GetBindingExpression(TextBox.TextProperty).DataItem).RollbackChanges(); 
       ((TextBox)sender).Text = string.Empty; 
      } 
      else if (e.Key == Key.Enter) 
      {     
       ((TextBox)sender).GetBindingExpression(TextBox.TextProperty).UpdateSource(); 
           } 
     } 

     public static void SetEscapeClearsText(DependencyObject dependencyObject, bool escapeClearsText) 
     { 
      if (!ReferenceEquals(null, dependencyObject)) 
       dependencyObject.SetValue(EscapeClearsTextProperty, escapeClearsText); 
     } 


     public static bool GetEscapeClearsText(DependencyObject dependencyObject) 
     { 
      if (!ReferenceEquals(null, dependencyObject)) 
       return (bool)dependencyObject.GetValue(EscapeClearsTextProperty); 
      return false; 
     } 


     #endregion Attached Property EscapeClearsText 
    } 

거기에 연결된 속성이있는 목록보기/gridview에 열이 도와주세요. 당신이 명시 적으로 UpdateSourceTrigger을 설정하면

<GridViewColumn Width="60"> 
              <GridViewColumnHeader Content="Priority" 
               Command="{Binding Path=SortSelectedClaimCodeGroupsCommand}" 
               CommandParameter="Item.IntPriority"> 
              </GridViewColumnHeader> 
              <GridViewColumn.CellTemplate> 
               <DataTemplate> 
                <Border DataContext="{Binding Item.Priority}" 
                 Style="{StaticResource ValidationResultBorderStyle}" HorizontalAlignment="Left" > 
                 <TextBox Width="200" MaxLength="25" Text="{Binding Path=Value,Mode=TwoWay,       
                  UpdateSourceTrigger=Explicit}" local:TextBoxBehavior.EscapeClearsText="True" > 

답변

1

, 당신은 명시 적으로 BindingExpression에서의 메소드 UpdateSource를 호출하여 소스를 업데이트해야합니다. 그 코드는 어디에 있습니까? 당신의 TextBoxKeyUp 이벤트에서

편집

당신은 당신의 Esc 키의 언론의 텍스트를 설정하여 바인딩 덮어 쓰기한다. 먼저 값을 속성 값에 바인딩하고 나중에 Textbox 텍스트 속성을 String.Empty로 명시 적으로 설정합니다.이 방법으로 텍스트 속성은 바인딩이 느슨해집니다. 따라서 나중에 UpdateSource를 호출 할 때마다 더 이상 원본 값으로 전파되지 않습니다.이 값은 더 이상 텍스트 상자의 Text 속성에 바인딩되어 있지 않기 때문입니다. 당신이 보존됩니다 바인딩이 방법

((TextBox)sender).SetCurrentValue(TextBox.TextProperty, String.Empty); 

및 UpdateSource는 정상적으로 작동합니다 - 대신이 같은 텍스트를 설정해야합니다.

+0

입력으로 "Enter 키"를 취할 첨부 된 속성을 사용하고 있습니다. – Relativity

+0

먼저 UpdateSourceTrigger가 UI 탭에 영향을 주어서는 안됩니다. 둘째, 소스를 업데이트하려고 할 때? Enter 키를 누르는 경우, 거기에 중단 점을 넣어서 연결된 속성에 대한 코드가 호출되는지 확인 했습니까? 여기에 코드를 붙이면 도움이 될 것입니다. –

+0

코드를 추가했습니다. 그리고 컨트롤에 중단 점을 넣음으로써 컨트롤이 왔는지 확인했습니다. – Relativity

관련 문제