我有一個圖片屬性的類:錯誤結合圖像類型屬性
...
public Image m_coverImage;
public Image CoverImage
{
get { return m_coverImage; }
set
{
m_coverImage = value;
//OnPropertyChanged(new PropertyChangedEventArgs("CoverImage"));
}
}
...
對此我綁定到用戶控件(名爲FullDescription)用彈出窗口:
...
<ContentControl Margin="5,0,20,0"
Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Center"
Content="{Binding CoverImage}"/>
...
形象以前加載並正確展示在父控件中(與上面的綁定方式相同),但是當我嘗試將其綁定到FullDescription UserControl時...
...
FullDescription descriptionPopup = new FullDescription();
descriptionPopup.DataContext = this.Ebook; //This line throw error
...
...我得到一個ArgumentException錯誤:
System.ArgumentException未處理 消息=該參數不正確。 堆棧跟蹤: 在MS.Internal.XcpImports.CheckHResult(UInt32的小時) 在MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper OBJ,的DependencyProperty屬性,DependencyObject的DOH) 在MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper DOH,屬性的DependencyProperty ,對象OBJ) 在System.Windows.DependencyObject.SetObjectValueToCore(的DependencyProperty DP,對象的值) 在System.Windows.DependencyObject.RefreshExpression(的DependencyProperty DP) 在System.Windows.Data.BindingExpression.RefreshExpression() 在系統。 Windows.Data.BindingExpression.SendDataToTarget() at System.Windows.Data.BindingExpression.SourceAquired() at System.Windows.Data.BindingExpression.Dat aContextChanged(對象O,DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs E) 在系統.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement .OnAncestorDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.Controls.Primitives.Popup.NotifyDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs E) 在System.Windows.FrameworkElement.OnPropertyChanged(的DependencyProperty DP) 在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 Mobiltec.Atheneum.Reader.WindowsPhone.Controls.EbookPhotoSummary System.Windows.FrameworkElement.set_DataContext(Object value) 。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) 在System.Windows.Controls.Control.OnMouseLeftButtonUp(控制CTRL,EventArgs的) 在MS.Internal.JoltHelper.FireEvent(IntPtr的unmanagedObj,IntPtr的unmanagedObjArgs,的Int32 argsTypeIndex,字符串eventName的) 在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)
任何想法?
在此先感謝。
我設法解決了這個問題。改變
<ContentControl Margin="5,0,20,0"
Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Center"
Content="{Binding CoverImage}"/>
爲
<Image Margin="5,0,20,0" Grid.Column="0" VerticalAlignment="Top"
HorizontalAlignment="Center" Source="{Binding CoverImage.Source}"/>
,一切工作正常。謝謝