Wpf 将StaticResource绑定到FrameworkElement';s属性

Wpf 将StaticResource绑定到FrameworkElement';s属性,wpf,data-binding,Wpf,Data Binding,我正在尝试使用Petzold的LineChartGenerator(从),它作为静态资源访问: <Window.Resources> <src:CensusData x:Key="censusData" /> <charts:LineChartGenerator x:Key="generator" ItemsSource="{Binding Source={StaticResource census

我正在尝试使用Petzold的LineChartGenerator(从),它作为静态资源访问:

 <Window.Resources>
    <src:CensusData x:Key="censusData" />
    <charts:LineChartGenerator 
            x:Key="generator"
            ItemsSource="{Binding Source={StaticResource censusData}}"
            Width="300"
            Height="200">
        </charts:LineChartGenerator.VerticalAxis>
    </charts:LineChartGenerator>
</Window.Resources>

但是我想将宽度和高度绑定到控件的当前宽度和高度。这不应该是:

 <charts:LineChartGenerator 
            x:Key="generator"
            ItemsSource="{Binding Source={StaticResource censusData}}"
            Width="{Binding ElementName=MyControl, Path=Width}"
            Height="200">

但这给了我一个绑定错误:找不到目标元素的治理FrameworkElement或FrameworkContentElement。BindingExpression:路径=宽度;DataItem=null;目标元素是“LineChartGenerator”(HashCode=52313994);目标属性为“宽度”(类型为“双精度”)

有可能这样做吗?我有各种各样的乱七八糟的东西,但它们都将控件的宽度设置为LineChartGenerator的宽度,这并不是理想的效果

谢谢

安德鲁

我相信,由于width属性位于窗口中。参考资料标记宽度绑定应该如下所示

Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
    AncestorType={x:Type Window}}, Path=ActualWidth}"