RadCombobox XML Binding?

10 posts, 0 answers
  1. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 01 Jul 2011 Link to this post

    Hi,

    i have this xml File:

    <?xml version="1.0" encoding="utf-8" ?>
    <MODULE>
        <Content>
            <ContentItems>
                <ContentItem>
                    <ContentCategoryName>Mandanten</ContentCategoryName>
                    <Attributes>
                        <Attribute AttributeGroup="Mandant">
                            <ContentAttribute AttributeName="Name">ERP</ContentAttribute>
                            <ContentAttribute AttributeName="Host">okljkj</ContentAttribute>
                            <ContentAttribute AttributeName="Port">6550</ContentAttribute>
                            <ContentAttribute AttributeName="mandant">eks</ContentAttribute>
                            <ContentAttribute AttributeName="pw">lolo</ContentAttribute>
                        </Attribute>
                    </Attributes>
                </ContentItem>
                <ContentItem>
                    <ContentCategoryName>Mandanten</ContentCategoryName>
                    <Attributes>
                        <Attribute AttributeGroup="Mandant">
                            <ContentAttribute AttributeName="Name">DEMO</ContentAttribute>
                            <ContentAttribute AttributeName="Host">jhkhjk</ContentAttribute>
                            <ContentAttribute AttributeName="Port">6551</ContentAttribute>
                            <ContentAttribute AttributeName="mandant">demo</ContentAttribute>
                            <ContentAttribute AttributeName="pw">lolo</ContentAttribute>
                        </Attribute>
                    </Attributes>
                </ContentItem>
            </ContentItems>
        </Content>
    </MODULE>

    and i don't now how to bind this File to an Combobox: How must the XMLDataProvider and the ComboboxItem look like?

    Thanks for helping me.
    Best Regrads
    Rene
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 04 Jul 2011 Link to this post

    Hi Wigl Wagl,

    Here are couple of example that show how you can use XmlDataProvider:
    http://joshsmithonwpf.wordpress.com/2007/06/04/binding-to-xml/

    http://blogs.msdn.com/b/ashish/archive/2006/09/19/762085.aspx

    Let us know if you need more information.

    Regards,
    Hristo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 05 Jul 2011 Link to this post

    Hi,

    hm thanks a lot, but can you give me an example which shows me the binding with my xml-Format?

    Thanks a lot
    Regards
    Rene
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 05 Jul 2011 Link to this post

    Hi Wigl Wagl,

    I cannot give you example with your xml because I don't know what you want to show in the combobox.
    You will have to use XPath in order to get the desired items.

    Kind regards,
    Hristo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 05 Jul 2011 Link to this post

    Hi,

    XML:
    <?xml version="1.0" encoding="utf-8" ?>
    <MODULE>
        <Content>
            <ContentItems>
                <ContentItem>
                    <ContentCategoryName>Mandanten</ContentCategoryName>
                    <Attributes>
                        <Attribute AttributeGroup="Mandant">
                            <ContentAttribute AttributeName="Name">ERP</ContentAttribute>
                            <ContentAttribute AttributeName="Host">okljkj</ContentAttribute>
                            <ContentAttribute AttributeName="Port">6550</ContentAttribute>
                            <ContentAttribute AttributeName="mandant">eks</ContentAttribute>
                            <ContentAttribute AttributeName="pw">lolo</ContentAttribute>
                            <ContentAttribute AttributeName="iocn">icon1.png</ContentAttribute>
                        </Attribute>
                    </Attributes>
                </ContentItem>
                <ContentItem>
                    <ContentCategoryName>Mandanten</ContentCategoryName>
                    <Attributes>
                        <Attribute AttributeGroup="Mandant">
                            <ContentAttribute AttributeName="Name">DEMO</ContentAttribute>
                            <ContentAttribute AttributeName="Host">jhkhjk</ContentAttribute>
                            <ContentAttribute AttributeName="Port">6551</ContentAttribute>
                            <ContentAttribute AttributeName="mandant">demo</ContentAttribute>
                            <ContentAttribute AttributeName="pw">lolo</ContentAttribute>
                            <ContentAttribute AttributeName="iocn">icon2.png</ContentAttribute>
                        </Attribute>
                    </Attributes>
                </ContentItem>
            </ContentItems>
        </Content>
    </MODULE>

    I want to see zhe Attribute Name and the icon as icon in the combobox

    Thanks, sorry but i get crazy with it..
    King Regards
    rene
  7. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 05 Jul 2011 Link to this post

    Hello Wigl Wagl,

    I'm not sure that I undertand you correctly but here is one possible solution to should all Atribute elements with template that show AttributeName and Icon:

    <Window x:Class="WpfApplication1.MainWindow"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <XmlDataProvider x:Key="source" Source="pack://application:,,,/WpfApplication1;component/XMLFile1.xml" XPath="//*[@AttributeName]" IsAsynchronous="False">
     
            </XmlDataProvider>
            <!--XPath="MODULE/Content/ContentItems/*"-->
            <!--XPath="//*[@AttributeName]"-->
        </Window.Resources>
        <Grid>
            <ComboBox VerticalAlignment="Center" HorizontalAlignment="Left" MinWidth="100"
                      ItemsSource="{Binding Source={StaticResource source}}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Image: " />
                                <TextBlock Text="{Binding XPath=@AttributeName\=\'iocn\'}" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Name: " />
                                <TextBlock Text="{Binding XPath=@AttributeName}" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
     
            </ComboBox>
        </Grid>
    </Window>

    I hope that this will help you.

    All the best,
    Hristo
    the Telerik team
    Register for the Q2 2011 What’s New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
  8. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 05 Jul 2011 Link to this post

    Thanks so much, this is briliant....

    But one mor Problem. I get my two Items, but like this in the ComboBox:

    Image:
    Name:
    Image:
    Name:

    But it should be like this:

    Image: icon1.png (later it should be an image)
    Name: ERP
    Image: icon2
    Name: Demo

    Regards from Ausrtia
    rene
  9. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 05 Jul 2011 Link to this post

    Hello Wigl Wagl,

    Then the XmlDataProvider XPath property should be:
    <XmlDataProvider x:Key="source" Source="pack://application:,,,/WpfApplication1;component/XMLFile1.xml" XPath="//Attributes/Attribute" ...

    Here are few good articles about XPath:
    http://msdn.microsoft.com/en-us/library/system.windows.data.binding.xpath.aspx

    http://www.w3schools.com/xpath/xpath_syntax.asp

    Best wishes,
    Hristo
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  10. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 05 Jul 2011 Link to this post

    Thanks the links a great, but..

    one more last question: Now the image ist static, how can i file the image source out of the xml file:

    Static:
    <ComboBox.ItemTemplate>
      <DataTemplate>
        <StackPanel Orientation="Horizontal">     
          <Image Source="/ERP-Manager;component/Images/icon4.png" Stretch="None" />                                                            
          <TextBlock Text="{Binding XPath=ContentAttribute[@AttributeName\=\'Name\']}" FontSize="14" Padding="5,4,0,0" />
        </StackPanel>                                                     
      </DataTemplate>
    </ComboBox.ItemTemplate>

    Dynamic:

    <ComboBox.ItemTemplate>
      <DataTemplate>
        <StackPanel Orientation="Horizontal">     
          <Image Source= ????  
          <TextBlock Text="{Binding XPath=ContentAttribute[@AttributeName\=\'Name\']}" FontSize="14" Padding="5,4,0,0" />
        </StackPanel>                                                     
      </DataTemplate>
    </ComboBox.ItemTemplate>

    Thanks so much
    Best Regards
    Rene
  11. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 06 Jul 2011 Link to this post

    Hi Wigl Wagl,

    You could save the URI in the xml and then directly bind Image Source property to the icon.
    <Image Source="{Binding IconPath}" Stretch="None" />

    Or you  could use IValueConverter and return different Icon based on the value of icon attribute.
    The xaml will be the same with one difference - you will have to specify Converter in the Binding:
    <Image Source="{Binding Icon, Converter={StaticResource StringToImageSourceConverter}" Stretch="None" />

    Then you have to implement IValueConverter and return different Images based on the string from xml.

    Regards,
    Hristo
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top
UI for WPF is Visual Studio 2017 Ready