Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How to reset datacontext to parent datacontext

 
 
Old 10-23-2006   #1 (permalink)
Pon


 
 

How to reset datacontext to parent datacontext

Hi,

I'm trying to suspend binding for the controls of a groupbox. To do that I
set its datacontext to null (nothing).
That's the first point that surprises me. It works ! I'm surprised
because I expected to see the groupbox retrieve its parent datacontext due
to dependency property inheritance mechanism. What do I miss there ?

But here comes the corollary problem : how to reset the datacontext to the
one of its parent ? If I try to force it with (vb code, sorry):
mygroupbox.datacontext = ctype(mygroupbox.parent,
frameworkelement).datacontext

it works... till the parent datacontext changes. The groupbox datacontext is
not linked (bound) to it.


How to achieve that ? What I want is just the default behavior after all. I
tried with DefaultMetadata.DefaultValue but it returns null and so doesn't
resolve my problem.

I have a working solution by binding the two datacontexts but I guess
there's something more direct (an ad-hoc method or something).

Thanx in advance.



My System SpecsSystem Spec
Old 10-23-2006   #2 (permalink)
Pon


 
 

Re: How to reset datacontext to parent datacontext

Ok I think I got it. It seems that the ClearValue method does the trick.
Right ?


"Pon" <pongla.public@laposte.net> a écrit dans le message de news:
uQeMz$o9GHA.4740@TK2MSFTNGP03.phx.gbl...
> Hi,
>
> I'm trying to suspend binding for the controls of a groupbox. To do that I
> set its datacontext to null (nothing).
> That's the first point that surprises me. It works ! I'm surprised
> because I expected to see the groupbox retrieve its parent datacontext due
> to dependency property inheritance mechanism. What do I miss there ?
>
> But here comes the corollary problem : how to reset the datacontext to the
> one of its parent ? If I try to force it with (vb code, sorry):
> mygroupbox.datacontext = ctype(mygroupbox.parent,
> frameworkelement).datacontext
>
> it works... till the parent datacontext changes. The groupbox datacontext
> is not linked (bound) to it.
>
>
> How to achieve that ? What I want is just the default behavior after all.
> I tried with DefaultMetadata.DefaultValue but it returns null and so
> doesn't resolve my problem.
>
> I have a working solution by binding the two datacontexts but I guess
> there's something more direct (an ad-hoc method or something).
>
> Thanx in advance.
>
>



My System SpecsSystem Spec
Old 10-24-2006   #3 (permalink)
Adam Smith [MS]


 
 

Re: How to reset datacontext to parent datacontext

Yup - you got it. There is most definitely a difference between a value
which is set (even if to null) and one which is not. As you found, setting
a local value - even null - overrides inheritance. And, as you found,
ClearValue "unsets" a local value, allowing inheritance to kick in again.

-Adam Smith [MS]

"Pon" <pongla.public@laposte.net> wrote in message
news:OIo59Fp9GHA.3352@TK2MSFTNGP03.phx.gbl...
> Ok I think I got it. It seems that the ClearValue method does the trick.
> Right ?
>
>
> "Pon" <pongla.public@laposte.net> a écrit dans le message de news:
> uQeMz$o9GHA.4740@TK2MSFTNGP03.phx.gbl...
>> Hi,
>>
>> I'm trying to suspend binding for the controls of a groupbox. To do that
>> I set its datacontext to null (nothing).
>> That's the first point that surprises me. It works ! I'm surprised
>> because I expected to see the groupbox retrieve its parent datacontext
>> due to dependency property inheritance mechanism. What do I miss there ?
>>
>> But here comes the corollary problem : how to reset the datacontext to
>> the one of its parent ? If I try to force it with (vb code, sorry):
>> mygroupbox.datacontext = ctype(mygroupbox.parent,
>> frameworkelement).datacontext
>>
>> it works... till the parent datacontext changes. The groupbox datacontext
>> is not linked (bound) to it.
>>
>>
>> How to achieve that ? What I want is just the default behavior after all.
>> I tried with DefaultMetadata.DefaultValue but it returns null and so
>> doesn't resolve my problem.
>>
>> I have a working solution by binding the two datacontexts but I guess
>> there's something more direct (an ad-hoc method or something).
>>
>> Thanx in advance.
>>
>>

>
>



My System SpecsSystem Spec
Old 10-25-2006   #4 (permalink)
Pon


 
 

Re: How to reset datacontext to parent datacontext

Thanx for confirming.

"Adam Smith [MS]" <Adam.Smith@microsoft.com> a écrit dans le message de
news: OGQRXU49GHA.748@TK2MSFTNGP02.phx.gbl...
> Yup - you got it. There is most definitely a difference between a value
> which is set (even if to null) and one which is not. As you found,
> setting a local value - even null - overrides inheritance. And, as you
> found, ClearValue "unsets" a local value, allowing inheritance to kick in
> again.
>
> -Adam Smith [MS]
>
> "Pon" <pongla.public@laposte.net> wrote in message
> news:OIo59Fp9GHA.3352@TK2MSFTNGP03.phx.gbl...
>> Ok I think I got it. It seems that the ClearValue method does the trick.
>> Right ?
>>
>>
>> "Pon" <pongla.public@laposte.net> a écrit dans le message de news:
>> uQeMz$o9GHA.4740@TK2MSFTNGP03.phx.gbl...
>>> Hi,
>>>
>>> I'm trying to suspend binding for the controls of a groupbox. To do that
>>> I set its datacontext to null (nothing).
>>> That's the first point that surprises me. It works ! I'm surprised
>>> because I expected to see the groupbox retrieve its parent datacontext
>>> due to dependency property inheritance mechanism. What do I miss there ?
>>>
>>> But here comes the corollary problem : how to reset the datacontext to
>>> the one of its parent ? If I try to force it with (vb code, sorry):
>>> mygroupbox.datacontext = ctype(mygroupbox.parent,
>>> frameworkelement).datacontext
>>>
>>> it works... till the parent datacontext changes. The groupbox
>>> datacontext is not linked (bound) to it.
>>>
>>>
>>> How to achieve that ? What I want is just the default behavior after
>>> all. I tried with DefaultMetadata.DefaultValue but it returns null and
>>> so doesn't resolve my problem.
>>>
>>> I have a working solution by binding the two datacontexts but I guess
>>> there's something more direct (an ad-hoc method or something).
>>>
>>> Thanx in advance.
>>>
>>>

>>
>>

>
>



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Using DataContext with WCF services .NET General
WPF - Binding IsEnabled property doesnt evaluate until DataContext .NET General


Vista Forums 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 Ltd

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