wpf 如何在 XAML 中将一个元素的属性绑定到另一个元素的属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9119032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to bind a property of one element to a property of another in XAML
提问by Hosea146
The following is some partial XAML:
以下是部分 XAML:
<CheckBox Content="Display Data Points?" Margin="8,0.04,0,4" Grid.Row="1" FlowDirection="RightToLeft" d:LayoutOverrides="Height" HorizontalAlignment="Left"/>
and
和
<vf:DataSeries RenderAs="Line" DataSource="{Binding CdTeRoughnessList}" XValueType="DateTime" MarkerEnabled="{Binding ???}" Color="Red" LegendText="Roughness Average">
I would like to bind the MarkerEnabledproperty of the DataSeries to the IsCheckedproperty of the CheckBox. In other words, when the user checks the check box, I want the MarkerEnabled to be set to True and False when unchecked.
我想将DataSeries 的 MarkerEnabled属性绑定到CheckBox的IsChecked属性。换句话说,当用户选中复选框时,我希望在未选中时将 MarkerEnabled 设置为 True 和 False。
Can this be done (I'm almost sure WPF would support this)? If so, how might I do it?
可以这样做吗(我几乎可以肯定 WPF 会支持这一点)?如果是这样,我该怎么做?
回答by The Real Baumann
Give your Checkbox a name and then bind appropriately:
为您的复选框命名,然后适当地绑定:
<CheckBox x:Name="DisplayDataCheckbox" Content="Display Data Points?"/>
<vf:DataSeries MarkerEnabled="{Binding ElementName=DisplayDataCheckbox, Path=IsChecked}">