Binder une DP sur son propre UserControl
Bonjour,
J'ai crée un userControl avec ses dependencyProproties et je souhaiterais binder ma DP à une propriété Text d'une TextBox.
Exemple :
Code:
1 2 3 4 5 6 7 8
| <UserControl x:Class="SilverlightControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<TextBlock Text="Hello, World" Name="tb" FontSize="{Binding MySize}"/>
</Grid>
</UserControl> |
Code:
<l:SilverlightControl1 x:Name="kuku" MySize="40"/>
J'ai un peu tout essayé mais rien ne marche.
J'ai cherché sur google et j'ai trouvé un billet parlant d'un bug.
Voici le billet : http://blogs.microsoft.co.il/blogs/t...-0-beta-2.aspx
Je voulais savoir si le "Bug", s'il en est un, a été corrigé et s'il n'y a pas une solution plus propre pour effectuer le binding souhaité.
Merci de votre réponse,
Steven
je pense que tout ce joue dans la definition de ta DP
bon voici ce qu'il faut faire pour rendre le binding effectif:
tu définie une proprièté qui correspond a ta dp voici l'exemple :
Code:
1 2 3 4 5 6 7 8 9 10 11
| public String Description
{
get
{
return (String)GetValue(DescriptionProperty);
}
set
{
SetValue(DescriptionProperty, value);
}
} |
ensuite tu enregistre ta dépendence
Code:
1 2
| public readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(String), typeof(Card), new PropertyMetadata(new PropertyChangedCallback(onDescriptionChanged))); |
et enfin tu donnes la définition du handler onDescriptionChanged
Code:
1 2 3 4 5
| public static void onDescriptionChanged(DependencyObject obj, DependencyPropertyChangedEventArgs dp)
{
Card a = obj as Card;
a.Description = dp.NewValue as string;
} |
et là je crois que ça va marcher .