Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind a property of one element to a property of another in XAML

Tags:

wpf

xaml

The following is some partial 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 MarkerEnabled property of the DataSeries to the IsChecked property 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.

Can this be done (I'm almost sure WPF would support this)? If so, how might I do it?

like image 629
Hosea146 Avatar asked Feb 02 '12 19:02

Hosea146


People also ask

What is two way binding in WPF?

Two way binding is used when we want to update some controls property when some other related controls property change and when source property change the actual control also updates its property.

What is element binding in WPF?

Element Binding: You can bind UI element to other UI element. <TextBox Name="txt1" Text="{Binding Path=EmpName}" /> <TextBox Name="txt2" Text="{Binding Path= Text, ElementName=txt1}" />

What is OneWay binding WPF?

In One Way binding, source control updates the target control, which means if you change the value of the source control, it will update the value of the target control. So, in our example, if we change the value of the slider control, it will update the textbox value, as shown below.


1 Answers

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}"> 
like image 174
The Real Baumann Avatar answered Sep 24 '22 03:09

The Real Baumann