Bonjour,
Je n'ai pas trouvé comment accéder à ma Dependency properties depuis le code XAML.
Mon code C#
et je voudrais donc avoir accès à mon Toto depuis XAML :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public partial class UserControl1 : UserControl { public static DependencyProperty TotoProperty = DependencyProperty.Register( "Toto", typeof(string), typeof(UserControl1)); public string Toto { get { return GetValue(TotoProperty) as string; } set { SetValue(TotoProperty, value); } } public UserControl1() { InitializeComponent(); }
et apparemment c'est pas aussi simple.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <UserControl x:Class="SandBox.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="300" Width="300"> <Grid> <Border Margin="4,4,25,0" Name="border1" BorderThickness="4" Height="110" VerticalAlignment="Top"></Border> <TextBlock Text="{Binding Toto}" Margin="22,116,15,82" /> </Grid> </UserControl>
J'ai cherché un peu partout et personne n'est vraiment clair (alors ou c'est trop simple et du coup les gens voyent plus loin ou ca a rien à voir ...)
Est ce que quelqu'un saurait me dire quelle est la méthode qui marche?
Partager