#134 – Dependency Property Value Sources: #1 – Local Value

The highest priority source for the base value of a dependency property is the property’s local value, set in XAML for the element that owns the property, or set from code.  If a local value is provided, it will override all other possible sources for the base value of the property.

In the following example, the 2nd Label provides a local value for the FontStyle property, overriding the inherited value.

<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525" FontStyle="Italic">
    <StackPanel Orientation="Vertical">
        <Button Content="Run" Height="23" Width="75" />
        <Button Content="Skip" Height="23" Width="75" />
        <StackPanel Orientation="Horizontal">
            <Label Content="Inside 2nd StackPanel"/>
            <Label x:Name="lblIndep" Content="I do my own FontStyle" FontStyle="Normal"/>

You can also set a local value from code:

            lblIndep.FontStyle = FontStyles.Normal;


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #134 – Dependency Property Value Sources: #1 – Local Value

  1. Pingback: #152 – Use ReadLocalValue() to Find the Local Value of a Dependency Property « 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: