- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试将 XDocument
绑定(bind)到 TreeView
控件。除属性外,一切正常。 #%*!$#@^% 不想出现:D
请帮助我修改该代码以使其工作:
<SolidColorBrush x:Key="xmlValueBrush" Color="Blue" />
<SolidColorBrush x:Key="xmAttributeBrush" Color="Red" />
<SolidColorBrush x:Key="xmlTagBrush" Color="DarkMagenta" />
<SolidColorBrush x:Key="xmlMarkBrush" Color="Blue" />
<DataTemplate x:Key="AttributeTemplate">
<StackPanel Orientation="Horizontal"
Margin="3,0,0,0"
HorizontalAlignment="Center">
<TextBlock Text="{Binding Path=Name}"
Foreground="{StaticResource xmAttributeBrush}" FontFamily="Consolas" FontSize="8pt" />
<TextBlock Text="=""
Foreground="{StaticResource xmlMarkBrush}" FontFamily="Consolas" FontSize="8pt" />
<TextBlock Text="{Binding Path=Value, Mode=TwoWay}"
Foreground="{StaticResource xmlValueBrush}" FontFamily="Consolas" FontSize="8pt" />
<TextBlock Text="""
Foreground="{StaticResource xmlMarkBrush}" FontFamily="Consolas" FontSize="8pt" />
</StackPanel>
</DataTemplate>
<HierarchicalDataTemplate x:Key="NodeTemplate">
<StackPanel Orientation="Horizontal" Focusable="False">
<TextBlock x:Name="tbName" Text="Root" FontFamily="Consolas" FontSize="8pt" />
<ItemsControl
ItemTemplate="{StaticResource AttributeTemplate}" HorizontalAlignment="Center"
ItemsSource="{Binding Path=Attributes}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
<HierarchicalDataTemplate.ItemsSource>
<Binding Path="Elements" />
</HierarchicalDataTemplate.ItemsSource>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
<Setter TargetName="tbName" Property="Text" Value="{Binding Path=Value, Mode=TwoWay}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="tbName" Property="Text" Value="{Binding Path=Name}" />
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
我的 TreeView
:
<TreeView x:Name="XmlTree" Grid.Row="1"
ItemsSource="{Binding Path=Root.Elements, UpdateSourceTrigger=PropertyChanged}"
ItemTemplate="{StaticResource NodeTemplate}"
SelectedItemChanged="XmlTree_SelectedItemChanged" />
这是我的代码:
private void BindXmlData(string filePath)
{
_xml = XDocument.Load(filePath);
XmlTree.DataContext = _xml;
}
所有节点都显示良好,但我无法通过属性使它们可见
最佳答案
您可以更改您的 DataTriggers 部分:
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="tbName" Property="Text" Value="{Binding Path=Name}" />
</DataTrigger>
收件人:
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="tbName" Property="Text" Value="{Binding Path=Name.LocalName}" />
</DataTrigger>
希望能帮到你,谢谢! - 假货
关于c# - 将 XDocument 绑定(bind)到 TreeView - 属性不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12052565/
我有一个将 XDocument 对象作为参数的函数。 我需要遍历不同集合中的许多其他对象,并针对这些对象中的每一个,在 XDocument 上执行一些操作。但是 lopp 的每次迭代都需要传递给函数的
下面的代码可以工作,但是很乱而且很慢。我正在使用带有 Saxon 的 XSLT2 将一个 XDocument 转换为另一个 XDocument,使用 SaxonWrapper 进行改编: public
我在 Visual Studio 2010 的 MVC4 Web API 应用程序中使用 XDocument,但不确定测试策略。 我的大部分单元测试都使用内存中的 XDocument,它适用于 Con
我无法使用 Linq 加载新的 XML 文档。那是我的代码: using System; using System.Collections.Generic; using System.Linq.Exp
抱歉,如果我的问题不清楚。我从 xDocument 中获得了一堆元素和每个元素的属性。现在我希望在每次迭代中获得每个节点的更多后代并遍历它们并获取它们的所有属性。 结构:
我接管了一个以二进制格式在 SQL Server 中存储大型 XML 文档的系统。 目前,数据是通过将其转换为字符串,然后将该字符串转换为字节数组来保存的。但最近在尝试转换为字符串时遇到一些大型 XM
我有一个使用 XDocument 构建 xml 文档的小应用程序。但是,一段时间后,该应用程序使用了超过 1GB 的内存。 所以我想知道是否有办法让 XDocument 使用磁盘而不是内存。例如,通过
我有一个像这样的 XDocument: 1057 Lookup_test open 1057 Lookup_test Waiting for input
如何将 xml 元素导入到对象?我下面的代码不起作用,它在 SetValue 处失败,我不明白为什么。 但即便如此,我怀疑 linq 有一种更简洁的方法来执行此操作,但我找不到任何示例。 class
我多年来一直通过 API 访问数据库,今天进行了更改,但我无法联系所有者。这似乎是一个微妙的变化,导致我的代码给出空引用异常。下载一个文件,然后我尝试使用 XmlReader 并使用以下代码将其加载到
我正在尝试将 XDocument 反序列化为包含数组/列表的类。问题是这段代码没有这样做,我总是得到一个没有任何库存项目的 Response 类(不是 null,但计数 = 0) 这是我的测试方法:
我正在使用 XDocument 来保存某种数据库。这个数据库由注册的聊天机器人组成,我只是有许多具有“用户名”、“所有者”等属性的“机器人”节点。然而,偶尔一些聪明人决定制作一个具有非常奇怪角色作为属
我有一个简化后的 xml 文档,如下所示: 有一个\t作为属性值。 执行这段代码时 var path = @"C:\test.xml"; var doc = XDocument.Load(path
当我尝试使用下一个代码加载一些 XML 文件时: XDocument configuration = XDocument.Load("%NAME_OF_THE_PATH%/Default_Te
我已经完成了研究并尝试了很多次试验,但这让我感到难过。我可能有点笨,但是鉴于以下 XML 文档,我怎样才能最轻松地找到 UnitTestResult 元素?
我需要将多个 namespace 添加到具有相同地址的 xdocument (C#) stuff and more stuff 如果我使用下面的代码添加..它只显示 xmlns:f XNames
如何从加载的 XDocument 中删除特定节点?我的 XML 文档如下所示: if (condition) { } ...
我有一个类似于 的 XDocument 我希望将属性 foo
很容易找到 Xdocument 属性的值,但是我们如何找到带有前缀/命名空间的属性。 XML 代码 My value 我正在尝试读取属性值 xlink:Id(其中 p 是 XElement) p =
我有以下 XML 文档: 我正在尝试使用 XDocument 解析此 XML,以便获得包含节点及其值的列表(字典): source => mysource,name
我是一名优秀的程序员,十分优秀!