Hello friends,
I want to extract the name property from selected item and pass it to a Elements(Xname) property,but don`t know how to convert it.Actually iam working on a filter consisting of two combo boxes and a texbox. Combobox1 is populated with selectedItem`s element(from xmldata) and combobox2 is contains selecteditem`s(xmldata) attribute.
<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" ItemsSource="{Binding}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox Margin="0,0,3,0" x:Name="cbox2" ItemsSource="{Binding XPath=@*}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox Margin="0,0,3,0" x:Name="cbox3">
<ComboBoxItem Content="Equals"/>
<ComboBoxItem Content="Greater Than"/>
<ComboBoxItem Content="Less Than"/>
</ComboBox>
<TextBox Margin="0,0,4,0" Width="50" x:Name="textbox2" />
<Button x:Name="but1" Height="25" Width="35" Click="click" Content="gen" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
The C# Code
private void click(object sender, RoutedEventArgs e)
{
try
{
var button = sender as Button;
var parent = button.Parent as FrameworkElement;
var attributebox = parent.FindName("cbox2") as ComboBox;
var textbl = parent.FindName("abc") as TextBlock;
var elementbox = parent.FindName("cbox1") as ComboBox;
var combobx = parent.FindName("cbox3") as ComboBox;
var textBox1 = parent.FindName("textbox2") as TextBox;
XElement ele = XElement.Load(txtFileName.Text);
var fil = from item in ele.DescendantsAndSelf(textbl.Text).Elements(elementbox.SelectedItem.ToString())
select item;
foreach (var f in fil)
{
Label lb = new Label();
lb.Content = f;
canvas1.Children.Add(lb);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"Invalid value");
}
}
All I want is to convert the selected combobox item to string,As i know the selectedItem properties contains object, and i want to extract the name property from the and as i cannot convert the whole object to a string....so please suggest me a way......