2008-10-31 9 views
5

मेरे पास एक सिल्वरलाइट 2 एप्लिकेशन है जो डेटा ऑनटैब चयन चेंज किया गया है। तुरंत मैंने यह शुरू करना शुरू किया कि UpdateSourceTrigger को केवल लॉस्टफोकस से अधिक की अनुमति है क्योंकि यदि आप नियंत्रण से टैबबिंग किए बिना टैब पर क्लिक करते हैं तो LINQ ऑब्जेक्ट को सत्यापन से पहले अपडेट नहीं किया जाता है।सिल्वरलाइट डाटाग्रिड पर UpdateSourceTrigger LostFocus के लिए वर्कअराउंड?

मैं वापस एक और नियंत्रित करने के लिए ध्यान देने की स्थापना करके बक्सें के लिए समस्या के काम किया और उसके बाद OnTextChanged:

Private Sub OnTextChanged(ByVal sender As Object, ByVal e As TextChangedEventArgs) 
    txtSetFocus.Focus() 
    sender.Focus() 
End Sub 

अब मैं एक डेटा ग्रिड के भीतर हैक का समान प्रकार पूरा करने के लिए कोशिश कर रहा हूँ। मेरा डेटाग्रिड CellTemplate और CellEditingTemplate के लिए रनटाइम पर जेनरेट किए गए डेटा टेम्पलेट का उपयोग करता है। मैंने TextTanged = "OnTextChanged" को DataTemplate में टेक्स्टबॉक्स में लिखने का प्रयास किया, लेकिन यह ट्रिगर नहीं हुआ है।

किसी के पास कोई विचार है?

+0

किसी को भी इस पर एक विचार है? –

उत्तर

6

You can do it with a behavior applied to the textbox too

// xmlns:int is System.Windows.Interactivity from System.Windows.Interactivity.DLL) 
// xmlns:behavior is your namespace for the class below 
<TextBox Text="{Binding Description,Mode=TwoWay,UpdateSourceTrigger=Explicit}"> 
    <int:Interaction.Behaviors> 
     <behavior:TextBoxUpdatesTextBindingOnPropertyChanged /> 
    </int:Interaction.Behaviors> 
</TextBox> 


public class TextBoxUpdatesTextBindingOnPropertyChanged : Behavior<TextBox> 
{ 
    protected override void OnAttached() 
    { 
     base.OnAttached(); 

     AssociatedObject.TextChanged += new TextChangedEventHandler(TextBox_TextChanged); 
    } 

    protected override void OnDetaching() 
    { 
     base.OnDetaching(); 

     AssociatedObject.TextChanged -= TextBox_TextChanged; 
    } 

    void TextBox_TextChanged(object sender, TextChangedEventArgs e) 
    { 
     var bindingExpression = AssociatedObject.GetBindingExpression(TextBox.TextProperty); 
     bindingExpression.UpdateSource(); 
    } 
} 
+0

यह मेरे लिए खूबसूरती से काम करता है, धन्यवाद – McAden

-2

मैं जानता हूँ कि यह पुरानी खबर है ... लेकिन मैं ऐसा करने से यह चारों ओर हो गया है:

पाठ = "{बाइंडिंग पथ = newQuantity, UpdateSourceTrigger = PropertyChanged}"

+2

चू, मैंने जो कुछ भी पढ़ा है, उससे एसएल 2 या एसएल 3 में UpdateSourceTrigger के लिए कोई प्रॉपर्टी चेंज पसंद नहीं है। –

+2

PropertyChanged WPF में UpdateSourceTrigger के लिए मूल्य है। – sparks

0

इस ब्लॉग पोस्ट अपडेट करने का तरीका पता चलता एक पाठ बॉक्स के स्रोत स्पष्ट रूप से जुड़ी संपत्ति का उपयोग कर: http://www.thomasclaudiushuber.com/blog/2009/07/17/here-it-is-the-updatesourcetrigger-for-propertychanged-in-silverlight/

आप आसानी से और साथ ही अन्य नियंत्रण के साथ काम करने के लिए इसे संशोधित कर सकता है ...

0

मैं MVVM और एस का उपयोग कर इस एक ही समस्या में पड़ गए ilverlight 4. समस्या यह है कि बाइंडिंग स्रोत को अद्यतन नहीं करता है जब तक कि टेक्स्टबॉक्स फोकस न हो जाए, लेकिन किसी अन्य नियंत्रण पर फ़ोकस सेट करना चाल नहीं करता है।

मुझे दो अलग-अलग ब्लॉग पोस्टों के संयोजन का उपयोग करके समाधान मिला। मैं

http://www.cauldwell.net/patrick/blog/DefaultButtonSemanticsInSilverlightRevisited.aspx

www.smallworkarounds.net/2010/02/elementbindingbinding-modes.html

मेरे परिवर्तन के परिणामस्वरूप SmallWorkarounds.net से एक "SmallWorkaround" के साथ पैट्रिक CAULDWELL के DefaultButtonHub अवधारणा से कोड का इस्तेमाल किया, DefaultButtonHub वर्ग के लिए निम्न कोड में:

public class DefaultButtonHub 
{ 
    ButtonAutomationPeer peer = null; 

    private void Attach(DependencyObject source) 
    { 
     if (source is Button) 
     { 
      peer = new ButtonAutomationPeer(source as Button); 
     } 
     else if (source is TextBox) 
     { 
      TextBox tb = source as TextBox; 
      tb.KeyUp += OnKeyUp; 
     } 
     else if (source is PasswordBox) 
     { 
      PasswordBox pb = source as PasswordBox; 
      pb.KeyUp += OnKeyUp; 
     } 
    } 

    private void OnKeyUp(object sender, KeyEventArgs arg) 
    { 
     if (arg.Key == Key.Enter) 
      if (peer != null) 
      { 
       if (sender is TextBox) 
       { 
        TextBox t = (TextBox)sender; 
        BindingExpression expression = t.GetBindingExpression(TextBox.TextProperty); 
        expression.UpdateSource(); 
       } 
       ((IInvokeProvider)peer).Invoke(); 
      } 
    } 

    public static DefaultButtonHub GetDefaultHub(DependencyObject obj) 
    { 
     return (DefaultButtonHub)obj.GetValue(DefaultHubProperty); 
    } 

    public static void SetDefaultHub(DependencyObject obj, DefaultButtonHub value) 
    { 
     obj.SetValue(DefaultHubProperty, value); 
    } 

    // Using a DependencyProperty as the backing store for DefaultHub. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty DefaultHubProperty = 
     DependencyProperty.RegisterAttached("DefaultHub", typeof(DefaultButtonHub), typeof(DefaultButtonHub), new PropertyMetadata(OnHubAttach)); 

    private static void OnHubAttach(DependencyObject source, DependencyPropertyChangedEventArgs prop) 
    { 
     DefaultButtonHub hub = prop.NewValue as DefaultButtonHub; 
     hub.Attach(source); 
    } 

} 

यह सिल्वरलाइट :)

के लिए प्रलेखन के कुछ प्रकार में शामिल किया जाना चाहिए
संबंधित मुद्दे