WPF ListView按钮继承字体颜色

时间:2014-01-14 23:27:14

标签: c# wpf listview

我正在尝试在listview列中创建一个“隐形”按钮。如何从ListViewItem获取一个继承字体颜色的按钮?

<ListView x:Name="lvHistory" ItemsSource="{Binding history}" BorderThickness="0" Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="2" util:GridViewSort.AutoSort="True" SizeChanged="lvHistory_SizeChanged">
    <ListView.View>
        <GridView>
            <GridViewColumn Width="Auto">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Button Click="cell_click" Tag="{Binding Serial}" Foreground="{INHERITSOMETHING}">

1 个答案:

答案 0 :(得分:2)

这会将按钮的前景绑定到与ListViewItem相同的

Foreground="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"