How to set an empty string with ChangePropertyAction RRS feed

  • Question

  • Hi,

    in my app I'd like to clear SearchBox QueryText through ChangePropertyAction in this way:

    <Button Content="Clear search">
    		<core:EventTriggerBehavior EventName="Tapped">
    			<core:ChangePropertyAction TargetObject="{Binding ElementName=SearchTextBox}" PropertyName="QueryText" Value="" />

    When I click the button, I get the following exception:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
       at System.StubHelpers.HStringMarshaler.ConvertToNativeReference(String managed, HSTRING_HEADER* hstringHeader)
       at Windows.UI.Xaml.Controls.SearchBox.put_QueryText(String value)
       --- End of inner exception stack trace ---
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

    I also tried to define an empty string in my resource dictionary and then bind ChanegPropertyAction Value to this string but I get the same exception:

    <x:String x:Key="EmptyString"></x:String>
    <core:ChangePropertyAction TargetObject="{Binding ElementName=SearchTextBox}" PropertyName="QueryText" Value="{StaticResource EmptyString}" />

    The only workaround I found is to define an empty TextBlock and bind to its text:

    <TextBlock Text="" x:Name="EmptyStringText" Visibility="Collapsed" />
    <core:ChangePropertyAction TargetObject="{Binding ElementName=SearchTextBox}" PropertyName="QueryText" Value="{Binding Text, ElementName=EmptyStringText}" />

    Is there a way to set an empty string through ChangePropertyAction in SearchBox QueryText?

    Sunday, January 26, 2014 7:16 AM

All replies

  • Hi,

    You can create the button Tapped event in code-behind and set the searchBox QueryText to null:

     private void Button_Tapped(object sender, TappedRoutedEventArgs e)
                searchbox.QueryText = "";
    Best Wishes!

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, January 27, 2014 7:34 AM
  • Hi,

    your solution works but I'd like to use ChangePropertyAction.

    Tuesday, January 28, 2014 5:07 AM