我想在listboxItem中添加工具提示,但是当有DisplayMemberPath时它会启动问题.错误信息说:无法同时设置DisplayMemberPath和ItemTemplate.当我删除DisplayMemberPath时,每个列表项中的工具提示都有效.但我不想删除DisplayMemember因为我需要它.如何解决这个问题呢?
<ListBox x:Name="lstToys" Style="{DynamicResource ListBoxStyle1}" ItemsSource="{Binding Strings}" DisplayMemberPath="Toys" MouseDoubleClick="lstToys_MouseDoubleClick">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" ToolTip="Here is a tooltip"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud) 如何使用C#以正确的方式获取属性"action"和"filename"值?
XML:
<?xml version="1.0" encoding="utf-8" ?>
<Config version="1.0.1.1" >
<Items>
<Item action="Create" filename="newtest.xml"/>
<Item action="Update" filename="oldtest.xml"/>
</Items>
</Config>
Run Code Online (Sandbox Code Playgroud)
C#:我无法获取属性值以及如何获取foreach循环中的值?怎么解决这个?
var doc = new XmlDocument();
doc.Load(@newFile);
var element = ((XmlElement)doc.GetElementsByTagName("Config/Items/Item")[0]); //null
var xmlActions = element.GetAttribute("action"); //cannot get values
var xmlFileNames= element.GetAttribute("filename"); //cannot get values
foreach (action in xmlActions)
{
//not working
}
foreach (file in xmlFileNames)
{
//not working
}
Run Code Online (Sandbox Code Playgroud)
您的代码示例对我来说意味着很多.谢谢!