I am working in WPF for converting bookmarks into xml doc and then binding the xml into tree view to display the bookmarks into tree view.
My code is:
<Window.Resources>
<HierarchicalDataTemplate x:Key="NodeTemplate"
ItemsSource="{Binding
XPath=./*}">
<TextBlock x:Name="nodetext"/>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding
Path=NodeType}" Value="Element">
<Setter TargetName="nodetext"
Property="Text" Value="{Binding
XPath = Title}" />
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"
/>
</Grid.RowDefinitions>
<TreeView Name="trvItems"
Grid.Row="0"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource
NodeTemplate}">
Using this:
<SetterTargetName="nodetext"Property="Text"Value="{BindingXPath=
Title}" />
I am getting simple text in display but not in tree view, need to display in tree view format.
CS code:
public MainWindow()
{
InitializeComponent();
}
private void btnAFM_Click(object sender, RoutedEventArgs e)
{
string filename = System.AppDomain.CurrentDomain.BaseDirectory;
filename = @"D:\xyz.pdf";
string outputbookmark = @"D:\abc.xml";
var Sbytes = File.ReadAllBytes(filename);
PdfReader pdfReader = new PdfReader(Sbytes);
IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pdfReader);
using (StreamWriter Sw = new StreamWriter(outputbookmark))
{
SimpleBookmark.ExportToXML(bookmarks, Sw, "ISO8859-1", true);
}
XmlDocument doc = new XmlDocument();
doc.Load(outputbookmark);
XmlDataProvider provider = new XmlDataProvider();
provider.Document = doc;
provider.XPath = "./*";
var bookmark = XmlParser<Bookmark>.Deserialize(outputbookmark);
trvItems.DataContext = provider;
}
}