![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | 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 |
My System Specs![]() |
| | #2 (permalink) |
| | 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 > |
My System Specs![]() |
| | #3 (permalink) |
| | 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? |
My System Specs![]() |
| | #4 (permalink) |
| | 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? |
My System Specs![]() |
| | #5 (permalink) |
| | 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. > |
My System Specs![]() |
| Thread Tools | |
| |