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 to reset datacontext to parent datacontext

Closed Thread
 
Thread Tools Display Modes
Old 10-23-2006   #1 (permalink)
Pon
Guest


 

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.


Old 10-23-2006   #2 (permalink)
Pon
Guest


 

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.
>
>



Old 10-24-2006   #3 (permalink)
Adam Smith [MS]
Guest


 

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.
>>
>>

>
>



Old 10-25-2006   #4 (permalink)
Pon
Guest


 

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.
>>>
>>>

>>
>>

>
>



Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using DataContext with WCF services Ragesh Krishna .NET General 1 2 Weeks Ago 02:27 AM
WPF - Binding IsEnabled property doesnt evaluate until DataContext Todd Beaulieu .NET General 1 03-06-2008 09:52 AM
About DataContext howen Avalon 0 05-22-2007 05:20 AM
using DataContext to bind from Page linked by Frame buzzweetman@gmail.com Avalon 1 04-24-2007 01:27 AM
Is binding a datacontext to a CLR object correct ? Pon Avalon 2 03-25-2007 05:31 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