I have a class with an Image property:
...
public Image m_coverImage;
public Image CoverImage
{
get { return m_coverImage; }
set
{
m_coverImage = value;
//OnPropertyChanged(new PropertyChangedEventArgs("CoverImage"));
}
}
...
Which I bind to an UserControl (named FullDescription) with a Popup:
...
<ContentControl Margin="5,0,20,0"
Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Center"
Content="{Binding CoverImage}"/>
...
The Image is previously loaded and is exhibited correctly in a parent Control (binded same way as above), but when I try to bind it to the FullDescription UserControl...
...
FullDescription descriptionPopup = new FullDescription();
descriptionPopup.DataContext = this.Ebook; //This line throw error
...
...I get an ArgumentException error:
System.ArgumentException was unhandled Message=The parameter is incorrect. StackTrace: at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh) at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper doh, DependencyProperty property, Object obj) at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value) at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp) at System.Windows.Data.BindingExpression.RefreshExpression() at System.Windows.Data.BindingExpression.SendDataToTarget() at System.Windows.Data.BindingExpression.SourceAquired() at System.Windows.Data.BindingExpression.DataContextChanged(Object o, DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e) at System.Windows.Controls.Primitives.Popup.NotifyDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnPropertyChanged(DependencyProperty dp) at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at System.Windows.FrameworkElement.set_DataContext(Object value) at Mobiltec.Atheneum.Reader.WindowsPhone.Controls.EbookPhotoSummary.hplMore_Click(Object sender, RoutedEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.HyperlinkButton.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) at Microsoft.Xna.Framework.Input.UnsafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) at Microsoft.Xna.Framework.Input.SafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) at Microsoft.Xna.Framework.Input.WindowMessageHooker.Hook.WndProc(IntPtr msgWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
Any ideas?
Thanks in advance.
I manage开发者_如何学Cd to solve the problem. Changed
<ContentControl Margin="5,0,20,0"
Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Center"
Content="{Binding CoverImage}"/>
for
<Image Margin="5,0,20,0" Grid.Column="0" VerticalAlignment="Top"
HorizontalAlignment="Center" Source="{Binding CoverImage.Source}"/>
and everything works fine. Thanks
Unfortunately the errors provided by the Silverlight framework are often very vague, as is the case here.
The best advice I can give you is to narrow down the problem. Simplify your code so that it is the smallest example that exhibits this problem. If you can provide a concise example, updates your question. At the moment it is far to vague to answer.
精彩评论