lpx

Hi,

I'm trying to implement a dependency property which feeds an Image element in the XAML side this way:

// dependency property declaration
public static readonly DependencyProperty actualImagePathProperty = DependencyProperty.RegisterAttached("actualImagePath", typeof(ImageSource), typeof(Slide), new FrameworkPropertyMetadata(null));
public static readonly DependencyProperty nextImagePathProperty = DependencyProperty.RegisterAttached("nextImagePath", typeof(ImageSource), typeof(Slide), new FrameworkPropertyMetadata(null));

// property wrapper
public ImageSource ActualImagePathProperty
{
get { return (ImageSource)GetValue(actualImagePathProperty); }
set { SetValue(actualImagePathProperty, value); }
}

public ImageSource NextImagePathProperty
{
get { return (ImageSource)GetValue(nextImagePathProperty); }
set { SetValue(nextImagePathProperty, value); }
}

// property manual filling for testing
this.SetValue(actualImagePathProperty,new BitmapImage(new Uri(@"C:\Documents and Settings\Nuno Santos\My Documents\testcontent\artemisestatua.jpg")));
this.SetValue(nextImagePathProperty, new BitmapImage(new Uri(@"C:\Documents and Settings\Nuno Santos\My Documents\testcontent\artemisestatua.jpg")));

I have no errors but no image is displayed. What is wrong

Thanx

Nuno




Re: Windows Presentation Foundation (WPF) Problems implementing dependency property that feeds image

Kent Boogaart

Hi,

You haven't included your XAML, but you should read http://msdn2.microsoft.com/en-us/library/ms753358.aspx#registering. Basically, you haven't followed conventions in your implementation. It should look more like:

Code Block

// dependency property declaration
public static readonly DependencyProperty ActualImagePathProperty =

DependencyProperty.RegisterAttached("ActualImagePath",

typeof(ImageSource),

typeof(Slide));


// property wrapper
public ImageSource ActualImagePath
{

get { return GetValue(ActualImagePathProperty) as ImageSource; }
set { SetValue(ActualImagePathProperty, value); }
}


//XAML

<Image Source="{Binding ActualImagePath, Source=...}"/>


HTH,
Kent




Re: Windows Presentation Foundation (WPF) Problems implementing dependency property that feeds image

lpx

Hi,

Yes, i forgot to included the XAML.

This is what i'm using:

<Image x:Name="actual" Height="Auto" Source="{Binding Path=ActualImagePathProperty}"

I also do this in the .cs side:

this.DataContext = this; (does it make any sense )

I have updated the code to look like what you gave me and now i have an error again:

System.Windows.Data Error: 35 : BindingExpression path error: 'ActualImagePathProperty' property not found on 'object' ''Slide' (Name='MainWindow')'. BindingExpressionStick out tongueath=ActualImagePathProperty; DataItem='Slide' (Name='MainWindow'); target element is 'Image' (Name='next'); target property is 'Source' (type 'ImageSource')

I dont understand your XAML, why do you say that the binding is

<Image Source="{Binding ActualImagePath, Source=...}"/>

Where is the path defined Why is source declared What should i put in the Source


Thx,


Nuno








Re: Windows Presentation Foundation (WPF) Problems implementing dependency property that feeds image

Kent Boogaart

Don't worry about the Source in my binding. If you've set up a DataContext then that's fine. I think the problem is just you've specified "ActualImagePathProperty" instead of just "ActualImagePath". Try changing that and let me know.

Kent




Re: Windows Presentation Foundation (WPF) Problems implementing dependency property that feeds image

Charles Petzold

There's a case discrepancy here. You have actualImagePageProperty beginning in lower-case but ActualImagePath beginning in upper-case. These should be consistent.





Re: Windows Presentation Foundation (WPF) Problems implementing dependency property that feeds image

lpx

That was the problem indeed!

Thx,

Nuno