祖先在一个风格中绑定?

时间:2012-12-25 19:31:00

标签: wpf styles relativesource

如何在样式中绑定Ancestor?

我想执行以下操作(尝试使列宽自动与列表视图对齐)

<Style x:Key="m_ListViewStyle" TargetType="{x:Type ListView}" x:Shared="False">
<Setter Property="View">
    <Setter.Value>
        <GridView>
            <GridViewColumn>
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        ...
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>

            <GridViewColumn Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"/>
        </GridView>
    </Setter.Value>
</Setter>

但是我收到了绑定错误 -

Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ListView', AncestorLevel='1''.

0 个答案:

没有答案