Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF工具提示数据绑定_C#_Wpf - Fatal编程技术网

C# WPF工具提示数据绑定

C# WPF工具提示数据绑定,c#,wpf,C#,Wpf,我正在尝试为ListView行创建工具提示。 用于生成listview的当前数据结构: public class Map { public string Name{get;set;} public List<Difficulty> Difficulties{get;set;} } public class Difficulty { public int ID{get;set;} public string Name{get;set;} } // I

我正在尝试为ListView行创建工具提示。 用于生成listview的当前数据结构:

public class Map
{
    public string Name{get;set;}
    public List<Difficulty> Difficulties{get;set;}
}

public class Difficulty
{
    public int ID{get;set;}
    public string Name{get;set;}
}

// Items to list are added like.
ListView.Items.Add(new Map(){....});
公共类映射
{
公共字符串名称{get;set;}
公共列表{get;set;}
}
公共课难度
{
公共int ID{get;set;}
公共字符串名称{get;set;}
}
//要添加到列表的项目如下所示。
添加(新映射(){….});
这是我的工具提示XAML代码:

<Setter Property="ToolTip">
    <Setter.Value>
        <ItemsControl ItemsSource="{Binding Difficulties}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.Column="0" Text="{Binding Name}" />
                        <TextBlock Grid.Column="1" Text="{Binding ID}" />
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Setter.Value>
</Setter>

这一切都是可行的,但我需要的是显示地图中的名称,而不是难度

试试看

Text="{Binding DataContext.Name, RelativeSource={RelativeSource AncestorType=ListViewItem}}"
试一试