V
Vivien Parlat
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>
===================================================
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>
===================================================