Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how can i use <x:array xmlns:x="#unknown"> for strings in xaml 4.0 for implementing dynamic resources in wpf application in which two combobox having 3 elements of string type
Posted
Comments
Sergey Alexandrovich Kryukov 19-Aug-14 12:06pm    
Not clear. What is your problem?
—SA
tusharkaushik 19-Aug-14 12:33pm    
i mean i want to use <x:array> in xaml 4.0 for implementing resource in which a combobox contains array of 3 strings but xaml 4.0 does not support ! it shows <x:arrayextensions instead="" of="" <x:array="">. how can i implement resources in wpf application.
Sergey Alexandrovich Kryukov 19-Aug-14 13:09pm    
First of all, it does support it. Second of all, you should not put data in XAML. Add the objects you want from your data using your code or binding. Read about binding; eventually, with XAML, you will have to use it.
—SA
tusharkaushik 19-Aug-14 14:14pm    
pls ! pls ! explain with example ! what do u mean by object adding!
ihave read the code from the link:
http://www.wpf-tutorial.com/wpf-application/resources/
tusharkaushik 19-Aug-14 14:15pm    
but it does not generate the correct output

1 solution

Do you mean a static resource? This would be declared in XAML (though this is bad from maintainability and extensibility aspects...)

Anyways, if you are looking for static resource then,

C#
// 1. In your Window tag declare usage of .NET System namespace

  <window x:class="WpfTutorialSamples.WPF_Application.ExtendedResourceSample" xmlns:x="#unknown">
          xmlns="http://schemas.microsoft.com/winfx/2010/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2010/xaml"
          xmlns:s="clr-namespace:System;assembly=mscorlib"
          Title="StaticResourceComboboxSample" 
          Height="400"
          Width="300">

// 2. Now, namespace alias 's' corresponds to System namespace in mscorlib.dll and this has the standard types defined.

// 3. Create a static resource, it has a key property which will be used later to use/associate this resource to a control e.g. combo-box in your case.

  <x:array x:key="CBXDropdownItems" type="s:String">
    <s:string xmlns:s="#unknown">A</s:string>
    <s:string xmlns:s="#unknown">B</s:string>
    <s:string xmlns:s="#unknown">C</s:string>
  </x:array>

// 4. Now all we have to do is associate this resource (key) to the control's data source (ItemsSource property).

  <combobox itemssource="{StaticResource CBXDropdownItems}" /></window>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900