Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .
Posted
Updated 18-Feb-13 20:59pm
v4

1 solution

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.
 
Share this answer
 
Comments
Abhinav_Sharma 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)



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