1

我正在尝试为 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(){....});

这就是我的工具提示 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>

一切正常,但我需要的是从Map中显示Name,而不是Difficulty

4

1 回答 1

1

尝试

Text="{Binding DataContext.Name, RelativeSource={RelativeSource AncestorType=ListViewItem}}"
于 2013-08-02T19:53:56.860 回答