Setting the DataContext of a HyperlinkButton with TemplateBinding results in a catastraphic failure in Blend RRS feed

  • Question

  • Hallo,

    I have the following problem:

    I have created a custom control (derived from Control) and a control template (in Generic.xaml).

    My control class has a property: TargerUri


            public Uri TargetUri
    get { return (Uri)GetValue(TargetUriProperty); }
    set { SetValue(TargetUriProperty, value); }

    // Using a DependencyProperty as the backing store for TargetUri. This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TargetUriProperty =
    DependencyProperty.Register("TargetUri", typeof(Uri), typeof(SearchResultGadget), new PropertyMetadata(new Uri("foo://example.com")) );

    In the control template I want to reformat the Uri to a different format. Therefor I created a value converter class (derived from IValueConverter):


        public class CClientStartPageUriBuilder : IValueConverter

    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    string strUri = String.Format("/CClientStartPage/{0}", ((Uri)value).ToString());
    Uri myUri = new Uri(strUri.Replace('\\', '/'));
    return myUri;

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    throw new NotImplementedException();


     In the control template I bind the NavigateUri property of a HyperlinkButton to the TargetUri of my control using template binding and the value converter:


    <HyperlinkButton x:Name="xTitle" 
    VerticalAlignment="Top" Foreground="#FFFF8700"
    DataContext="{TemplateBinding TargetUri}"
    NavigateUri="{Binding Converter={StaticResource UriBuilder}}"
    Content="{TemplateBinding Title}" FontFamily="Tahoma" FontSize="16" Margin="0,0,0,3">
    <DropShadowEffect Direction="255" ShadowDepth="0" BlurRadius="11"/>

    This works fine in the compiled version, but Blend (version 3.0.1927.0) prevents me from editing the control template. The error is:

     An exception was thrown.

    Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))


    at MS.Internal.XcpImports.MethodEx(IntPtr prt, String name, CValue[] cvData)

    at System.Windows.UIElement.UpdateLayout()

    InnerException: None


    If I remove the line

    DataContext="{TemplateBinding TargetUri}" 

    the error in Blend is gone and I can edit the template (but of course the template bindig is broken now).

     Any ideas? This is really ginig me a headache.

    Is this a Blend issue, or am I doing something wrong?

    Your feedback is very much appreciated!

    I already changed the type of my TargetUri property to string (and in the value converter as well) but this doesn't seem to change anything.

    Btw. I am working with Silverlight 3.

    Tuesday, February 9, 2010 5:30 AM

All replies

  •  "Catastrophic failure" gives us nothing, I saw many people report this failure in different situation, I found this article today about debugging design time exception, maybe you can have a try to find some useful information about the exception


    Thursday, February 11, 2010 2:06 AM
  • I did that. This is the call stack, when the exception occurs: 


    > System.Windows.dll!System.Windows.DependencyObject.SetValueInternal(System.Windows.DependencyProperty dp, object value = {"value"}, bool allowReadOnlySet, bool isSetByStyle, bool isSetByBuiltInStyle, System.Windows.PropertyInvalidationReason reason) + 0x562 bytes 
      System.Windows.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) + 0x11 bytes 
      Microsoft.Expression.Platform.Silverlight.dll!Microsoft.Expression.Platform.Silverlight.SilverlightFrameworkElementDesignTimeProperties.DataContextPropertyChangedCallback(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0xd5 bytes 
      System.Windows.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications(System.Windows.DependencyProperty dp = {System.Windows.CustomAttachedDependencyProperty}, object newValue, object oldValue) + 0x4c bytes 
      System.Windows.dll!System.Windows.DependencyObject.SetValueInternal(System.Windows.DependencyProperty dp, object value, bool allowReadOnlySet, bool isSetByStyle, bool isSetByBuiltInStyle, System.Windows.PropertyInvalidationReason reason) + 0x50f bytes 
      System.Windows.dll!MS.Internal.FrameworkCallbacks.SetTemplateBindingCustomToCustom(System.IntPtr source, uint nSourcePropertyID, System.IntPtr target, uint nTargetPropertyID) + 0xfc bytes 
      [Native to Managed Transition] 
      [Managed to Native Transition] 


    (... Removed unecessary noise ...)

    Thursday, February 11, 2010 3:56 AM