473,503 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataBinding through aggregation

Hello,

Here is the description of the code I have:

- a class myClass, inheriting from DependencyObject, containing a
DependencyProperty myString (yes, my names are ugly)
- a class toStringConverter implementing IValueConverter, which takes
a myClass and returns its myString
- the following XAML code (see below).

When I click on the top button, only the first string is modified,
because the second textblock is bound not to the property, but to the
object.

My question itself is simple: how can I automatically update the
second textblock when myString property is modified ? I only need such
a binding in OneWay mode, so how can I "notify" wpf engine to reflect
any modification of the myString value like if it was a modification
of the container itself ? (keeping the same syntax; I simplified the
example so I don't have the flexibility to do it the first textblock's
way).

Thanks in advance

============= the xaml code ===============================

<Window x:Class="WpfApplication6.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication6"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<my:myClass x:Key="maClasse" myString="AbC" />
<my:toStringConverter x:Key="ToStCo" />
</Window.Resources>
<Grid DataContext="{StaticResource maClasse}">
<StackPanel Orientation="Vertical">
<Button Click="Button_Click">Go</Button>
<TextBlock Text="{Binding myString}"/>
<TextBlock>
<TextBlock.Text>
<Binding Converter="{StaticResource ToStCo}" />
</TextBlock.Text>
</TextBlock>
</StackPanel>
</Grid>
</Window>
================================================== =
Jun 27 '08 #1
1 1129
"Vivien Parlat" <po****@gmail.comwrote in message
news:3b**********************************@j22g2000 hsf.googlegroups.com...
Hello,

Here is the description of the code I have:

- a class myClass, inheriting from DependencyObject, containing a
DependencyProperty myString (yes, my names are ugly)
- a class toStringConverter implementing IValueConverter, which takes
a myClass and returns its myString
- the following XAML code (see below).

When I click on the top button, only the first string is modified,
because the second textblock is bound not to the property, but to the
object.

My question itself is simple: how can I automatically update the
second textblock when myString property is modified ? I only need such
a binding in OneWay mode, so how can I "notify" wpf engine to reflect
any modification of the myString value like if it was a modification
of the container itself ? (keeping the same syntax; I simplified the
example so I don't have the flexibility to do it the first textblock's
way).

Thanks in advance

============= the xaml code ===============================

<Window x:Class="WpfApplication6.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication6"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<my:myClass x:Key="maClasse" myString="AbC" />
<my:toStringConverter x:Key="ToStCo" />
</Window.Resources>
<Grid DataContext="{StaticResource maClasse}">
<StackPanel Orientation="Vertical">
<Button Click="Button_Click">Go</Button>
<TextBlock Text="{Binding myString}"/>
<TextBlock>
<TextBlock.Text>
<Binding Converter="{StaticResource ToStCo}" />
</TextBlock.Text>
</TextBlock>
</StackPanel>
</Grid>
</Window>
================================================== =
I'm certainly no expert on WPF, but as far as I know there's no simple way
to do what you want. I can think of one rather nasty way round which I think
will work, but I don't recommend it!

1. Implement INotifyPropertyChanged in myClass.
2. Define another property on myClass which just returns "this", e.g.:
public MyClass Me { get { return this; } }
3. In the PropertyChangedCallback for the myString dependency property fire
a change notification for the new property:
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Me"));
4. Change the XAML to bind to the new property instead of to the object::
<TextBlock Text="{Binding Me, Converter={StaticResource ToStCo}}" />

Chris Jobson

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2903
by: Nice Chap | last post by:
Aggregation in COM was defined as 'Exposing an interface of an inner object by the outer object as though it were an interface of the outer object'. Is this type of aggregation possible in c#? ...
5
3765
by: John Wood | last post by:
Let's say you're provided with an instance of a class. The instantiation takes place in another module that you have no control over. However, you've extended that class with your own value-added...
2
2616
by: Jozsef Bekes | last post by:
Hi, I would like to implement aggregation in C#, therefore I'd need to implement the queryinterface COM function of a class. I am not sure whether this can be done, and if yes where to start. If...
4
14437
by: Frederik Vanderhaegen | last post by:
Hi, Can anyone explain me the difference between aggregation and composition? I know that they both are "whole-part" relationships and that composition parts are destroyed when the composition...
23
2100
by: SenthilVel | last post by:
Hi Can any one let me know the websites/Pdf for learning Aggragation in C#?? Thanks Senthil
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.