Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
codexaml
<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
 
        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
Edited 18-Feb-13 20:59pm
v4

1 solution

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

Solution 1

Abhinav
 
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.
 
Thanks.
  Permalink  
Comments
Abhinavkpit007 at 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
0 Sergey Alexandrovich Kryukov 6,725
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,589
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
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