Binding Problem:



  • Ich habe problem Daten in eine "Inneren" Datencontent z binden!

    folgende ContentWrapper Control:

    public partial class ContentWrapper : UserControl
    	{
    		public ContentWrapper()
    		{
    			InitializeComponent();
    		}
    
    		public object MyOwnContent
    		{
    			get { return (object)GetValue(MyOwnContentProperty); }
    			set { SetValue(MyOwnContentProperty, value); }
    		}
    
    		// Using a DependencyProperty as the backing store for MyOwnContent.  This enables animation, styling, binding, etc...
    		public static readonly DependencyProperty MyOwnContentProperty =
    			DependencyProperty.Register("MyOwnContent", typeof(object), typeof(ContentWrapper), new UIPropertyMetadata(null));
    
    	}
    

    XMAL:

    <UserControl x:Class="WpfApplication1.ContentWrapper"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" 
                 d:DesignHeight="300" d:DesignWidth="300" x:Name="root">
        <Grid DataContext="{Binding ElementName=root}">
    		<Border BorderBrush="Red" BorderThickness="2">
    			<ContentControl Content="{Binding MyOwnContent}"></ContentControl>
    		</Border>
    	</Grid>
    </UserControl>
    

    Nun die verwendung:

    <StackPanel>
    		<WpfApplication1:ContentWrapper>
    			<WpfApplication1:ContentWrapper.MyOwnContent>
    // DIESE BINING GEHT
    				<TextBlock Text="{Binding MyText}">
    </TextBlock>
    				</WpfApplication1:ContentWrapper.MyOwnContent>
    			</WpfApplication1:ContentWrapper>
    // DIESE BINING GEHT NICHT (da es im content ist!?!?
    			<TextBlock Text="{Binding MyText}"></TextBlock>
    		</StackPanel>
    

    Welche keinligkeit mach ich falsch?

    Danke



  • P.S. Anderes herum beim GEHT UND GEHT NICHT !! SORRY 😞



  • Woher weißt du denn, dass das Binding nicht funktioniert? Wie ist die Binding Fehlermeldung im Ausgabefenster?



  • Das seh ich, da der inhalt nur in einem textblock angezeigt ist!

    Die Fehlermneldung ist, dass das Property "MyText" nicht im DataContent Context vorhanden ist... was ja auch stimmt!

    Ich dachte das ginge ohne probleme , jetzt muss ich den datenkontext rein verbiegen.. gefällt mir nich)


Anmelden zum Antworten