When i want to xml data load to the combobox . i got this solution. Its very simple to load the xml data. this the xml data.

<Items>
  <Item>
    <ItemId>1</ItemId>
    <ItemName>Architecting ASP.NET Applications
                 eBook</ItemName>
    <Price>19.95</Price>
  </Item>
  <Item>
    <ItemId>2</ItemId>
    <ItemName>Fundamentals of N-Tier eBook</ItemName>
    <Price>19.95</Price>
  </Item>
     ...
     ...
  <Item>
    <ItemId>3</ItemId>
    <ItemName>Security for ASP.NET Developers
                 eBook</ItemName>
    <Price>19.95</Price>
  </Item>
</Items>
this is stackpanel resource load, it will load on window loaded
<StackPanel.Resources>
  <XmlDataProvider x:Key="ItemsData"
                   Source="/Items.xml"
                   XPath="Items/Item" />
</StackPanel.Resources>
Its a combobox wirte like this, i loaded in ItemName if you want price load to another one combobox just change the xPath and then automatically load the price data to the combobox.
<ComboBox Name="Items" MinWidth="200" Style="{StaticResource RequiredComboBox}" Foreground="Black" FontSize="30" IsSynchronizedWithCurrentItem="False" SelectedIndex="0">
                    <ComboBox.ItemContainerStyle>
                        <Style TargetType="ComboBoxItem">
                            <Setter Property="Padding" Value="5">
                            </Setter>
                        </Style>
                    </ComboBox.ItemContainerStyle>
                    <ComboBox.ItemsSource>
                        <Binding Source="{StaticResource ItemsData}" XPath="ItemName" />
                    </ComboBox.ItemsSource>
                </ComboBox>

0 comments

Related Posts Plugin for WordPress, Blogger...