Click here to Skip to main content
15,885,757 members

Filter xml data present as a object using linq to xml

Abhinav_Sharma asked:

Open original thread
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
codexaml
HTML
<ListView Height="222" HorizontalAlignment="Left" Margin="341,24,0,0" Name="listView1" VerticalAlignment="Top" Width="290" removed="Green" 
                  AllowDrop="True" 
                  DragDrop.Drop="listview_drop" 
                  DragDrop.DragEnter="treeview_dragenter" ItemsSource="{Binding XPath=self::*}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <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"/>
                        </ComboBox>
                        <TextBox Margin="0,0,3,0" Width="50" x:Name="textbox1" />
                        <Button x:Name="but1" Height="25" Width="35" Click="click" Content="gen" />
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>



And the c# code behind

C#
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 .
Tags: C# (C# 4.0), XML, WPF, LINQ

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900