【发布时间】:2010-12-15 19:50:09
【问题描述】:
我试图弄清楚如何在 xaml 中构建递归绑定。我知道 HierarchialDataTemplate,但这不是我想要的,因为我的数据源不是项目的集合。具体来说,我正在构建一个异常浏览器,并试图找出表达异常的 InnerException 字段的最佳方式(这当然是另一个异常,因此是递归。)
这个异常浏览器是我正在构建的日志查看器的一部分。到目前为止,这是 ListView 的 XAML:
<ListView x:Name="LogViewerOutput">
<ListView.ItemTemplate>
<DataTemplate DataType="Ushanka.Log.LogMessageEventArgs">
<Expander Style="{StaticResource ExceptionTreeStyle}" Width="Auto">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<Image Stretch="Fill" Width="16" Height="16" Margin="5"
Source="{Binding Path=Level, Converter={StaticResource LogLevelIconConverter}}" />
<TextBlock Text="{Binding Message}" />
</StackPanel>
</Expander.Header>
<Expander.Content>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Exception.Message}" />
<TextBlock Text="{Binding Exception.Source" />
<!-- Here I would like to somehow be able to recursively browse through the tree of InnerException -->
</StackPanel>
</Expander.Content>
</Expander>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
有什么想法吗?这甚至可能吗?
【问题讨论】: