Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<pre lang="sql">I want to know Add items in Combobox and binding in Code Behind.I just tried with xml binding.
Below IS my XML file.

<pre lang="xml"><?xml version="1.0" encoding="utf-8" ?>
    <Month Name="JAN"/>
    <Month Name="FEB"/>
    <Month Name="MAR"/>
    <Month Name="APR"/>
    <Month Name="MAY"/>
    <Month Name="JUN"/>
    <Month Name="JUL"/>
    <Month Name="AUG"/>
    <Month Name="SEP"/>
    <Month Name="OCT"/>
    <Month Name="NOV"/>
    <Month Name="DEC"/>
    <Day Value="01"/>
    <Day Value="02"/>
    <Day Value="03"/>
    <Day Value="04"/>
    <Day Value="05"/>
    <Day Value="06"/>
    <Day Value="07"/>
    <Day Value="08"/>
    <Day Value="09"/>
    <Day Value="10"/>
    <Day Value="11"/>
    <Day Value="12"/>
    <Day Value="13"/>
    <Day Value="14"/>
    <Day Value="15"/>
    <Day Value="16"/>
    <Day Value="17"/>
    <Day Value="18"/>
    <Day Value="19"/>
    <Day Value="20"/>
    <Day Value="21"/>
    <Day Value="22"/>
    <Day Value="23"/>
    <Day Value="24"/>
    <Day Value="25"/>
    <Day Value="26"/>
    <Day Value="27"/>
    <Day Value="28"/>
    <Day Value="29"/>
    <Day Value="30"/>
    <Day Value="31"/>
    <Year year="1985"/>
    <Year year="1986"/>
    <Year year="1987"/>
    <Year year="1988"/>
    <Year year="1989"/>
    <Year year="1990"/>
    <Year year="1991"/>
    <Year year="1992"/>
    <Year year="1993"/>
    <Year year="1994"/>
    <Year year="1995"/>
    <Year year="1996"/>
    <Year year="1997"/>
    <Year year="1998"/>

And I Binded in XAML like.,

        <XmlDataProvider x:Key="getdate" Source="../Comboload.xml" XPath="/DateOfYear/Day_of_Year_odd/Day" />
        <XmlDataProvider x:Key="getmonth" Source="../Comboload.xml" XPath="/DateOfYear/Month_of_Year/Month" />
        <XmlDataProvider x:Key="getyear" Source="../Comboload.xml" XPath="/DateOfYear/Year_of_year/Year" />

<ComboBox ItemsSource="{Binding Source={StaticResource getdate}}" DisplayMemberPath="@Value"  Height="23" Name="comboBox1" Width="50"/>
            <ComboBox ItemsSource="{Binding Source={StaticResource getmonth}}" DisplayMemberPath="@Name" Height="23" Name="comboBox2" Width="55" />
            <ComboBox ItemsSource="{Binding Source={StaticResource getyear}}" DisplayMemberPath="@year" SelectedItem="{Binding SelectedOption1}" Height="23" Name="comboBox3" Width="55" />
Updated 8-May-14 2:02am
[no name] 8-May-14 6:43am    
Okay... I would want to know what have you tried? What would be the problem with what you have tried? Have you read the FAQ for how to ask a question?
WPF_Mvvm 8-May-14 8:00am    
yeah sorry,I updated my question
[no name] 8-May-14 8:18am    
Okay and? Just dumping code here is not a question or a description of any kind of a problem
WPF_Mvvm 8-May-14 8:30am    
I wanted to know how to add those date,Month,year in to 3 comboboxes. I achieved by the way I mentioned above. And I wanted to know how it can be done through properties.
Hope you got my question.
[no name] 8-May-14 12:27pm    
Okay... so again... what have you tried? There is not a single property in your example code. There is not a single line of C# code here where you have attempted anything at all to solve whatever your problem actually is.

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