Problème d'initialisation d'une DependencyProperty dans un UserControl
Bonjour,
J'ai créé un UserControl dans lequel je place entre autre un label.
Ce que j'aimerai c'est que le développeur passe un chemin de fichier en paramètre de mon UserControl et que celui-ci affiche ce chemin précédé d'un message.
Du coup, j'ai fait ça :
- XAML du UserControl
Code:
1 2 3 4 5 6 7 8 9 10 11
|
<UserControl x:Class="MyNamespace.MyControl" x:Name="myControl">
<Grid DataContext="{Binding Source=myControl}">
[...]
<Label x:Name="confFileLabel"
Grid.Row="1"
Grid.Column="1"
Content="{Binding ElementName=myControl, Path=CurrentConfigurationPath}" />
</Grid>
</UserControl> |
- Code du UserControl :
Code:
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
|
namespace MyNamespace
{
public partial class MyControl : UserControl
{
public DependencyProperty CurrentConfigurationPathProperty = DependencyProperty.Register(
"CurrentConfigurationPath", typeof(string), typeof(BannerControl));
public BannerControl()
{
InitializeComponent();
}
public string CurrentConfigurationPath
{
get
{
return (string)GetValue(CurrentConfigurationPathProperty);
}
set
{
// Valid reference?
if (value == null || value.Trim().Length == 0)
{
throw new Exception("Invalid path(" + value + ")");
}
else
{
SetValue(CurrentConfigurationPathProperty, "Current configuration: " + value);
}
}
}
}
} |
- XAML où on crée le UserControl:
Code:
1 2
|
<utils:MyControl x:Name="myControl1" CurrentConfigurationPath="c://toto"/> |
En gros, j'ai essayé de rajouter "Current configuration: " à la propriété saisie.
Malheureusement, il ne m'écrit que "c://toto" et non pas "Current configuration: c://toto".
Quelqu'un voit pourquoi ?
Merci d'avance.
PS : j'ai aussi essayé de rajouter le "préfixe" sur le get de ma propriété, mais c'est pareil...