After going through StackOverflow yesterday, I found a solution to the problem of binding an XML document to a treeview in an answer here. It worked like a charm, with one problem: now I have a blank line at the top of each node, one for each immediate child it has.
I'm at a loss as to how to get rid of it.
Here's the XML:
<Window.Resources>
<outboundInterfaceTestService:TrueToVisibleConverter x:Key="TrueToVisibleConverter" />
<outboundInterfaceTestService:TrueToCollapsedConverter x:Key="TrueToCollapsedConverter" />
<HierarchicalDataTemplate x:Key="NodeTemplate">
<TextBlock x:Name="text" Text="" />
<HierarchicalDataTemplate.ItemsSource>
<Binding XPath="child::node()|attribute::*" />
</HierarchicalDataTemplate.ItemsSource>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
<Setter TargetName="text" Property="Foreground" Value="Red" />
<Setter TargetName="text" Property="Text" Value="{Binding Path=Value}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="text" Property="Text" Value="{Binding Path=Name}" />
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
</Window.Resources>
<!-- snip! -->
<!-- later on, the TreeView itself -->
<TreeView Name="ContentTree"
Grid.Row="3"
ItemsSource="{Binding Path=SelectedItem.ContentXmlDoc}"
ItemTemplate="{StaticResource NodeTemplate}"
Visibility="{Binding Path=SelectedItem.IsError,
Converter={StaticResource TrueToCollapsedConverter}}">
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
Here, unfortunately, is what it looks like. I've circled the blank areas, though really they're pretty obvious -- at least, the big block is; the little one could be mistaken for padding, but it's not.
Any thoughts? I can't get rid of that TextBlock because it's used by the DataTriggers, so I don't know what I'm missing here. And, it being my first time trying this, I'm not even sure where to start.
Update Here's the XML, by request:
<?xml version='1.0' encoding='UTF-8'?>
<DataUpdate>
<EndpointId></EndpointId>
<MessageId></MessageId>
<UpdateList>
<ChargeItem>
<TenantId></TenantId>
<PatientId></PatientId>
<LastName></LastName>
<FirstName></FirstName>
<PatientGender></PatientGender>
<EncounterId></EncounterId>
<AttPhysicianId></AttPhysicianId>
<AttPhysicianLast></AttPhysicianLast>
<TransactionId></TransactionId>
<TransactionDate></TransactionDate>
<PostingDate></PostingDate>
<TransactionCode></TransactionCode>
<TransactionDesc></TransactionDesc>
<TransactionAltDesc></TransactionAltDesc>
<TransactionQuantity></TransactionQuantity>
<TransactionAmount></TransactionAmount>
<TransactionUnitAmt></TransactionUnitAmt>
<DepartmentCode></DepartmentCode>
<InsurancePlanId></InsurancePlanId>
<InsuranceAmount></InsuranceAmount>
<PatientLocation></PatientLocation>
<FeeScheduleId></FeeScheduleId>
<Patienttype></Patienttype>
<DiagnosisCode></DiagnosisCode>
<DiagnosisText></DiagnosisText>
<DiagnosisCodeType></DiagnosisCodeType>
<PerformedById></PerformedById>
<PerformedByLast></PerformedByLast>
<PerformedByFirst></PerformedByFirst>
<OrderedById></OrderedById>
<OrderedByLast></OrderedByLast>
<OrderedByFirst></OrderedByFirst>
<UnitCost></UnitCost>
<FillerOrderNumber></FillerOrderNumber>
<EnteredById></EnteredById>
<EnteredByLast></EnteredByLast>
<EnteredByFirst></EnteredByFirst>
<ProcedureCode></ProcedureCode>
<ProcedureCodeMod></ProcedureCodeMod>
<NdcCode></NdcCode>
</ChargeItem>
<ChargeItem>
<TenantId></TenantId>
<PatientId></PatientId>
<LastName></LastName>
<FirstName></FirstName>
<PatientGender></PatientGender>
<EncounterId></EncounterId>
<AttPhysicianId></AttPhysicianId>
<AttPhysicianLast></AttPhysicianLast>
<TransactionId></TransactionId>
<TransactionDate></TransactionDate>
<PostingDate></PostingDate>
<TransactionCode></TransactionCode>
<TransactionDesc></TransactionDesc>
<TransactionAltDesc></TransactionAltDesc>
<TransactionQuantity></TransactionQuantity>
<TransactionAmount></TransactionAmount>
<TransactionUnitAmt></TransactionUnitAmt>
<DepartmentCode></DepartmentCode>
<InsurancePlanId></InsurancePlanId>
<InsuranceAmount></InsuranceAmount>
<PatientLocation></PatientLocation>
<FeeScheduleId></FeeScheduleId>
<Patienttype></Patienttype>
<DiagnosisCode></DiagnosisCode>
<DiagnosisText></DiagnosisText>
<DiagnosisCodeType></DiagnosisCodeType>
<PerformedById></PerformedById>
<PerformedByLast></PerformedByLast>
<PerformedByFirst></PerformedByFirst>
<OrderedById></OrderedById>
<OrderedByLast></OrderedByLast>
<OrderedByFirst></OrderedByFirst>
<UnitCost></UnitCost>
<FillerOrderNumber></FillerOrderNumber>
<EnteredById></EnteredById>
<EnteredByLast></EnteredByLast>
<EnteredByFirst></EnteredByFirst>
<ProcedureCode></ProcedureCode>
<ProcedureCodeMod></ProcedureCodeMod>
<NdcCode></NdcCode>
</ChargeItem>
</UpdateList>
</DataUpdate>