473,246 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

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 1124
"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
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
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
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
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
by: SenthilVel | last post by:
Hi Can any one let me know the websites/Pdf for learning Aggragation in C#?? Thanks Senthil
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

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.