<TextBlock FontSize="{Binding ElementName=sliderFontSize, Path=Value}" />You will change "ElementName" to one of the following:
Source - The object supplying the data.
RelativeSource - Allows binding to another object relative to the element you are on. It could be Self, a parent, a descendant or a previous item in a list.
DataContext - When Source and RelativeSource are not specified, WPF searches up the tree to find if the DataContext property is set on any elements. DataContext holds the Source for all elements inside it.
How to bind a data object (class that holds your data - usually just one row) to a window:
1. Create a class that has public properties on it.
2. Add bindings to the elements that will be displaying your data.
3. Set the DataContext of the container that will be displaying your data.
Example:
1. Create the Data Object
public class Person { public string FirstName { get; set; } public string LastName { get; set; } }2. Create your Bindings
<Grid Name="gridPerson"> <TextBox Text="{Binding Path=FirstName}" /> <TextBox Text="{Binding Path=LastName}" /> </Grid>Note: The field name used for Path is CASE SENSITIVE. Your application will not generate a build error either. If your data is not showing up, check the case of the field name.
3. Set the DataContext (in this case, it is set in your code)
gridPerson.DataContext = App.Database.GetPerson();Note:
DataContext = App.Database.GetPerson();is valid also. Using gridPerson.DataContext just narrows the scope and makes the data only available to elements within gridPerson.