4

スタイル内で祖先にバインドするにはどうすればよいですか?

私は次のことをしたいです(列幅を自動的にリストビューに合わせようとしています)

<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''.
4

0 に答える 0