Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
sir ! i've written the following code in wpf 4.0 for string demo :
HTML
MainWindow.xaml
<window x:class="WpfApplication1.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" Height="350" Width="525"
        removed="{DynamicResource windowsBackgroundBrush}">
    <window.resources>
        <sys:string x:key="ComboBoxTitle" xmlns:sys="#unknown">items</sys:string>
        <x:array x:key="ComboBoxItems" type="sys:String">
            <sys:string xmlns:sys="#unknown">item#1</sys:string>
            <sys:string xmlns:sys="#unknown">item#2</sys:string>
            <sys:string xmlns:sys="#unknown">item#3</sys:string>
        </x:array>
        <lineargradientbrush x:key="windowsBackgroundBrush">
            <gradientstop offset="0" color="Chocolate" />
            <gradientstop offset="1" color="Aqua" />       
            </lineargradientbrush>
    </window.resources>
    <stackpanel margin="10" removed="PowderBlue">
        <Label Content="{StaticResource ComboBoxTitle}"></Label>
        <combobox itemssource="{StaticResource ComboBoxItems}"></combobox>
    </stackpanel>
    

</window>

-------------------------------------------------------------
but exception generated is :
Cannot convert the value in attribute 'ItemsSource' to object of type 'System.Collections.IEnumerable'. 'System.Windows.Markup.ArrayExtension' is not a valid value for property 'ItemsSource'. Error at object 'System.Windows.Controls.ComboBox' in markup file 'WpfApplication1;component/mainwindow.xaml' Line 21 Position 19.
------------------------------------------------------------------------------------
but if i write <x:array extension="" xmlns:x="#unknown"> then it's not accepting!
what could be the cause of this exception
Posted
Updated 16-Aug-14 2:24am
v2
Comments
[no name] 16-Aug-14 8:29am    
You need to figure out how to post your code. You also need to learn how to post your actual code. Get yourself a decent book on basic programming and work through it. We can't teach you programming one question at a time.
You error message means exactly what it says. An array is not valid for ItemsSource.

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