gamlieldor gamlieldor - 1 month ago 15
C# Question

XAML static string array with empty string

I have a combo box in my WPF application with a static item source (HTTP methods)

<ComboBox x:Name="methodsComboBox" Width="120"
ItemsSource="{StaticResource ResourceKey=Methods}"
SelectedItem="{Binding Object.Method, Mode=TwoWay}"/>


The static resource is a string array and looks like this:

<x:Array x:Key="Methods" Type="{x:Type sys:String}">
<sys:String>GET</sys:String>
<sys:String>POST</sys:String>
<sys:String>OPTIONS</sys:String>
<sys:String>PUT</sys:String>
<sys:String>DELETE</sys:String>
<sys:String>HEAD</sys:String>
<sys:String>TRACE</sys:String>
</x:Array>


How can I put an empty string inside so I will have a default value for my combo box? Something like this:

<sys:String> </sys:String>


When I do this, I get a runtime error (
NullArgumentException
).

Thanks.

Answer

Use

<x:Static Member="sys:String.Empty" />