WPF binding-Benutzer-Steuerelement mit Daten in C# - code

Habe ich create user control so:

public partial class View
    {
        public View()
        {
            InitializeComponent();
        }

        public static DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(TeaserView) );

        public string Name
        {
            get { return (string)GetValue(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

    }

XAML:

<UserControl x:Class="Controls.View"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="200" Width="164">
    <Grid VerticalAlignment="Stretch"
          x:Name="Preview">

        <Label Height="28"  Content="{Binding ElementName=Preview, Path=Name}" Background="LightYellow" x:Name="name" VerticalAlignment="Top" ></Label>
    </Grid>
</UserControl>

und verwenden Sie es in Window1 einfach in XAML:

<controls:View Height="200" Name="View1" Width="164" />

und ich versuche den Inhalt in C# (Name-Eigenschaft in diesem Beispiel), aber es macht ' N der Arbeit, Etikett, Inhalt ist immer noch leer. (Alle refereces, etc. gut sind), Was ist falsch?

InformationsquelleAutor Kamilos | 2009-09-25

Schreibe einen Kommentar