如何将项目添加到组合框并将其绑定到MVVM中

如何将项目添加到组合框并将其绑定到MVVM中

本文介绍了如何将项目添加到组合框并将其绑定到MVVM中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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" ?>
<DateOfYear>
  <Month_of_Year>
    <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"/>
  </Month_of_Year>
  <Day_of_Year>
    <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"/>
  </Day_of_Year>
  <Year_of_year>
    <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"/>
  </Year_of_year>
</DateOfYear>









我和XAML一样喜欢。,







And I Binded in XAML like.,

<Window.Resources>
        <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" />
    </Window.Resources>

<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" />

推荐答案

这篇关于如何将项目添加到组合框并将其绑定到MVVM中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 14:45