Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

How can I alter the dependency property inheritance chain?

Closed Thread
 
Thread Tools Display Modes
Old 04-28-2006   #1 (permalink)
Pascal Bourque
Guest


 

How can I alter the dependency property inheritance chain?

Hi,

I would like to alter the default inheritance chain for certain
dependency properties, but can't figure out how to do it properly.

For example, let's say I have this logical tree:

<StackPanel TextBlock.FontSize="18">
<TextBlock Text="First TextBlock (inherited FontSize)" />

<TextBlock FontSize="8" Text="Second TextBlock (explicit FontSize)" />

<TextBlock Text="Third TextBlock (inherited FontSize)" />
</StackPanel>

The current inheritance behavior makes the first and the third
TextBlocks have a FontSize of 18 (inherited from the StackPanel) and the
second TextBlock a FontSize of 8 (explicitly set).

My goal is to make the third TextBlock inherit its FontSize from the
second TextBlock.

The "Property value Inheritance" SDK topic does not cover this, and the
only thing I could find in the DependencyProperty system that seems to
relate to what I want to do is
FrameworkPropertyMetadata.OverridesInheritanceBehavior.

But then again, this is not documented very well and I could not find
any discussion about it on the web...

Does anyone has some information and/or experience to share on this topic?

Thanks!

Pascal
Old 04-28-2006   #2 (permalink)
viliescu
Guest


 

RE: How can I alter the dependency property inheritance chain?

I don't think it's possible to use inheritance in this case. What about
databinding? Is there any reason you cannot databind FontSize for the third
TextBox to the FontSize of the second one?
--
Valentin Iliescu [MVP - Client Application Development]


"Pascal Bourque" wrote:

> Hi,
>
> I would like to alter the default inheritance chain for certain
> dependency properties, but can't figure out how to do it properly.
>
> For example, let's say I have this logical tree:
>
> <StackPanel TextBlock.FontSize="18">
> <TextBlock Text="First TextBlock (inherited FontSize)" />
>
> <TextBlock FontSize="8" Text="Second TextBlock (explicit FontSize)" />
>
> <TextBlock Text="Third TextBlock (inherited FontSize)" />
> </StackPanel>
>
> The current inheritance behavior makes the first and the third
> TextBlocks have a FontSize of 18 (inherited from the StackPanel) and the
> second TextBlock a FontSize of 8 (explicitly set).
>
> My goal is to make the third TextBlock inherit its FontSize from the
> second TextBlock.
>
> The "Property value Inheritance" SDK topic does not cover this, and the
> only thing I could find in the DependencyProperty system that seems to
> relate to what I want to do is
> FrameworkPropertyMetadata.OverridesInheritanceBehavior.
>
> But then again, this is not documented very well and I could not find
> any discussion about it on the web...
>
> Does anyone has some information and/or experience to share on this topic?
>
> Thanks!
>
> Pascal
>

Old 04-28-2006   #3 (permalink)
Pascal Bourque
Guest


 

Re: How can I alter the dependency property inheritance chain?

The reason I'd prefer not to use data binding is because I would like
this to work transparently for many properties, without having to
explicitely setup bindings for those properties.

The DependencyProperty inheritance behavior really does what I want,
except, that I would like to find a way to modify the default
inheritance chain (i.e. specify what "parent" element to inherit the
property value from, even if that element is not a physical parent in
the logical or visual tree).

viliescu wrote:
> I don't think it's possible to use inheritance in this case. What about
> databinding? Is there any reason you cannot databind FontSize for the third
> TextBox to the FontSize of the second one?

Old 04-28-2006   #4 (permalink)
Ifeanyi Echeruo [MSFT]
Guest


 

Re: How can I alter the dependency property inheritance chain?

We dont support altering the inheritance chain.

There may be a supported solution for what you need; productivity-wise not
functionality-wise.

I suspect your scenario has been simplified to the point where the solutions
that jump at me may conflict with unstated constraints.

<!-- take advantage of quirks in stackpanel layout and use another
stackpanel to group items -->
<StackPanel TextBlock.FontSize="18">
<TextBlock Text="First TextBlock (inherited FontSize)" />
<StackPanel TextBlock.FontSize="8" /* other inherited properties */ >
<!-- same layout different inheritance chain -->
<TextBlock Text="Second TextBlock (inherited FontSize)" />
<TextBlock Text="Third TextBlock (inherited FontSize)" />
<StackPanel>
</StackPanel>

Or -- I think this is a 'cleaner' solution

<!-- explicitly style similar items -->

<StackPanel TextBlock.FontSize="18">
<StackPanel.Resources>
<Style x:Name="similarItems" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="8" />
<!-- other properties -->
</Style>
</StackPanel.Resources>

<TextBlock Text="First TextBlock (inherited FontSize)" />
<TextBlock Style="similarItems" Text="Second TextBlock (styled
FontSize)" />
<TextBlock Style="similarItems" Text="Third TextBlock (styled
FontSize)" />
</StackPanel>

-- Ifeanyi Echeruo [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.

"Pascal Bourque" <bourquep@xceedsoft.com> wrote in message
news:uK6yoAvaGHA.1348@TK2MSFTNGP05.phx.gbl...
> The reason I'd prefer not to use data binding is because I would like this
> to work transparently for many properties, without having to explicitely
> setup bindings for those properties.
>
> The DependencyProperty inheritance behavior really does what I want,
> except, that I would like to find a way to modify the default inheritance
> chain (i.e. specify what "parent" element to inherit the property value
> from, even if that element is not a physical parent in the logical or
> visual tree).
>
> viliescu wrote:
>> I don't think it's possible to use inheritance in this case. What about
>> databinding? Is there any reason you cannot databind FontSize for the
>> third TextBox to the FontSize of the second one?



Old 05-01-2006   #5 (permalink)
Pascal Bourque
Guest


 

Re: How can I alter the dependency property inheritance chain?

Indeed, there are some unstated constraints which prevent me from using
your proposed workarounds.

I am working on a workaround that seems like it could work, I'll post it
here when/if I get it working!

Thanks!

Pascal

Ifeanyi Echeruo [MSFT] wrote:
> We dont support altering the inheritance chain.
>
> There may be a supported solution for what you need; productivity-wise not
> functionality-wise.
>
> I suspect your scenario has been simplified to the point where the solutions
> that jump at me may conflict with unstated constraints.
>

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
WPF: Autogenerate a Private Dependency Property ? Jules Winfield .NET General 4 03-06-2008 09:43 AM
Binding to a custom dependency property diffeq Avalon 1 07-02-2007 01:42 PM
Does the dependency property inheritance mechanism only work between class and subclasses ? Pon Avalon 4 12-03-2006 04:39 AM
Trigger on user dependency property Griff Avalon 1 01-31-2006 06:59 AM
Dependency property not initialized in OnPropertyChanged? Jared Bienz Avalon 0 01-10-2006 03:53 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50