ElementName绑定失败 [英] ElementName Binding is failing
问题描述
我有以下XAML:
<Grid>
<Grid.RowDefinitions>
...
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" ...>
<DataGrid.Columns>
...
</DataGrid.Columns>
</DataGrid>
<DockPanel Grid.Row="2">
<CheckBox x:Name="DisplayMarkers" DockPanel.Dock="Top" Content="Display Data Points?"
Margin="8,5,0,5" d:LayoutOverrides="Height" HorizontalAlignment="Left" IsChecked="False" />
<vf:Chart DockPanel.Dock="Top" ScrollingEnabled="False" ZoomingEnabled="True" ToolBarEnabled="True">
<vf:DataSeries AxisYType="Secondary" RenderAs="Line" DataSource="{Binding CdTeRoughnessList}"
XValueType="DateTime"
MarkerEnabled="{Binding ElementName=DisplayMarkers, Path=IsChecked}" Color="Navy"
LegendText="Roughness Std. Dev.">
此绑定失败: MarkerEnabled ={Binding ElementName = DisplayMarkers,Path = IsChecked}
我试图绑定到名为DisplayMarkers的复选框上的IsChecked属性,当我运行这个调试模式在VS 2010中,输出窗口显示绑定失败,找不到名为复选框的元素,有没有人可以告诉我为什么?
I'm trying to bind to the IsChecked property on my Checkbox named 'DisplayMarkers". When I run this, in debug mode in VS 2010, the output window shows the binding is failing. It can't find the element named 'Checkbox'. Could anyone tell me why?
错误我从VS得到的是:
The error I'm getting from VS is:
System.Windows.Data Error: 4 : Cannot find source for binding with reference
'ElementName=DisplayMarkers'. BindingExpression:Path=IsChecked; DataItem=null; target element is 'DataSeries' (Name=''); target property is 'MarkerEnabled' (type 'Nullable`1')
推荐答案
你可能没有一个可以尝试绑定的命名空间,您可以尝试使用 Source = {x:Reference来替换
ElementName
You might not have a namescope where you try to bind, you could try to replace the ElementName
construct with Source={x:Reference DisplayMarkers}
.
有关潜在的循环依赖性错误的解决方法,请参阅: http://stackoverflow.com/a/6858917/546730
For a workaround for potential cyclical dependency errors see: http://stackoverflow.com/a/6858917/546730
这篇关于ElementName绑定失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!