![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 |
| | #2 (permalink) |
| 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 > |
| | #3 (permalink) |
| 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? |
| | #4 (permalink) |
| 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? |
| | #5 (permalink) |
| 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. > |
| |
| |
![]() |
| 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 |