Note that there are some explanatory texts on larger screens.

plurals
  1. POSet a property from type 'type' with global style in XAML
    primarykey
    data
    text
    <p>I would like to set a dependency property from type 'Type' in xaml. This will work fine but when I set this value in an implicit or explicit styling then a exception will thrown (unhandled exception).</p> <p>I created an empty Silverlight application and added a user control (DataFormControl). Here is the code behind of this control:</p> <pre><code> public DataFormControl() { InitializeComponent(); } public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(DataFormControl), null); public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } public static readonly DependencyProperty TypeToReflectProperty = DependencyProperty.Register("TypeToReflect", typeof(Type), typeof(DataFormControl), null); public Type TypeToReflect { get { return (Type)GetValue(TypeToReflectProperty); } set { SetValue(TypeToReflectProperty, value); } } public string GetCombo() { string returnValue = (Title ?? "no title") + " ; " + (TypeToReflect != null ? TypeToReflect.Name : "unkown Type"); return returnValue; } private void Refresh_Button(object sender, RoutedEventArgs e) { this.ResultBox.Text = GetCombo(); } </code></pre> <p>And here the XAML code:</p> <pre><code>&lt;Grid x:Name="LayoutRoot"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Button Click="Refresh_Button"&gt;Refresh&lt;/Button&gt; &lt;TextBlock x:Name="ResultBox" /&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p>Now the problem occurres in a control which reference this and use global styling:</p> <pre><code>&lt;StackPanel&gt; &lt;StackPanel.Resources&gt; &lt;Style TargetType="local:DataFormControl"&gt; &lt;Setter Property="Title" Value="Implicit Name" /&gt; &lt;Setter Property="TypeToReflect" Value="local:DataFormControl" /&gt; &lt;/Style&gt; &lt;/StackPanel.Resources&gt; &lt;TextBlock FontWeight="Bold"&gt;Test App&lt;/TextBlock&gt; &lt;local:DataFormControl Title="123" /&gt; &lt;local:DataFormControl Title="Kuh" /&gt; &lt;local:DataFormControl TypeToReflect="local:DataFormControl" /&gt; &lt;local:DataFormControl /&gt; &lt;/StackPanel&gt; </code></pre> <p>If I remove the "TypeToReflect"-Setter then all work fine. The global styling for the title property works fine too.</p> <p>Is this a bug or is there a workaround?</p> <p>I need the type because I would like to use reflection on it.</p> <p><em>Edit:</em></p> <p>Exception information:</p> <pre><code>Message is always. [Line: 0 Position: 0] ExceptionType: Unhandled Exception ExceptionObject: XamlParseException </code></pre> <p><strong>Stacktrace</strong>:</p> <pre><code> at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.ConvertStringToTypedCValue(IntPtr pContext, UInt32 cClrTypeName, String clrTypeName, UInt32 cValue, String value, CValue&amp; outVal, Int32&amp; typeIndex) at MS.Internal.SilverlightTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) at MS.Internal.XcpImports.GetManagedPropertyValueFromStyle(Boolean useBuiltInStyle, IManagedPeerBase obj, DependencyProperty property, Object&amp; value) at System.Windows.FrameworkElement.GetValueFromStyle(DependencyProperty property, Object&amp; value) at System.Windows.DependencyObject.EvaluateBaseValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry&amp; newEntry, ValueOperation operation) at System.Windows.DependencyObject.EvaluateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, ValueOperation operation) at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry&amp; newEntry, ValueOperation operation) at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty property) at MS.Internal.FrameworkCallbacks.InvalidateProperty(IntPtr nativeTarget, UInt32 propertyId) </code></pre> <p>InnerException is null.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload