【发布时间】:2011-12-11 19:00:35
【问题描述】:
我正在尝试使用作为 StaticResource 访问的 Petzold 的 LineChartGenerator(来自 http://msdn.microsoft.com/en-us/magazine/ee291567.aspx):
<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。绑定表达式:路径=宽度;数据项=空;目标元素是'LineChartGenerator' (HashCode=52313994);目标属性是“宽度”(类型“双”)
可以这样做吗?我有各种 kludges 但他们都将控件的宽度设置为 LineChartGenerator 的宽度,这确实不是预期的效果!
谢谢
安德鲁
【问题讨论】:
标签: wpf data-binding