Click here to Skip to main content
12,895,801 members (46,817 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# XML WPF LINQ C#4.0
hello friends,
I want to filter xmldata present as a item source of dynamically generated stack panel consisting of textblock,combobox and textbox.What i want is since textblock displays the selected element(which i have already figured out) user should select a filter criteria from the combobox and add text to the textbox and based on 3 filters,,it should filter and should display the filtered content.On searching the internet i found that linq to xml was a feasilble way.

here is the xaml
<ListView Height="222" HorizontalAlignment="Left" Margin="341,24,0,0" Name="listView1" VerticalAlignment="Top" Width="290" removed="Green" 
                  DragDrop.DragEnter="treeview_dragenter" ItemsSource="{Binding XPath=self::*}">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" x:Name="stc">
                        <TextBlock Text="{Binding Path=Name}" Margin="0,0,3,0" x:Name="abc"/>
                        <ComboBox Margin="0,0,3,0" x:Name="cbox1">
                            <ComboBoxItem Content="Less Than"/>
                            <ComboBoxItem Content="Greater Than"/>
                            <ComboBoxItem Content="Equals"/>
                        <TextBox Margin="0,0,3,0" Width="50" x:Name="textbox1" />
                        <Button x:Name="but1" Height="25" Width="35" Click="click" Content="gen" />

And the c# code behind

        private void click(object sender, RoutedEventArgs e)
            var button = sender as Button;
            var parent = button.Parent as FrameworkElement;
            var textBox = parent.FindName("textbox1") as TextBox;
            var textbl = parent.FindName("abc") as TextBlock;
            var com=parent.FindName("cbox1")as ComboBox;
            Xelement filter= (Xelement)((XmlDataProvider)Resources["xmlDataProvider"]).Data;

My problem is that on working with xelement,Iam getting a invalid type exception that it cannot convert system.xml.xmldocument to system.xml.linq .
Posted 18-Feb-13 20:53pm
Updated 18-Feb-13 20:59pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


This is because the right hand side statement return XDocument and left hand side is XElement.

Either, you take XDocument on left side and then convert it into XElement or use XDocument.

I hope, this might resolved the problem.

Abhinavkpit007 19-Feb-13 6:23am
Thanks a lot sanjay, that gave me a path to my work.........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100