昨天经过StackOverflow之后,我找到了一个解决方案,解决了在答案here中将XML文档绑定到树视图的问题。它就像一个魅力,有一个问题:现在我在每个节点的顶部都有一个空行,每个节点都有一个空白行。
我对如何摆脱它感到茫然。
这是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>
不幸的是,这就是它的样子。我已经圈出了空白区域,但实际上它们非常明显 - 至少,大块是;小家伙可能被误认为是填充,但事实并非如此。
有什么想法?我无法摆脱TextBlock,因为它被DataTriggers使用,所以我不知道我在这里缺少什么。而且,这是我第一次尝试这个,我甚至不确定从哪里开始。
更新 这是XML,按要求:
<?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>