Exception in LocExtension when being used by blend designer
Posted: 26 Feb 2024, 23:48
I've been tracking down an issue in the blend designer where an exception is being thrown when rendering one of my views.
I have a user control that looks like this:
I'm using this user control in another xaml:
I have a xaml using a custom control:
and the problem I'm seeing is that an exception is being thrown from the loc extension in LocExtension.cs, line 46, in the ProvideValue function:
This is the exception being thrown:
I'm not sure what I might be doing wrong exactly. I'll keep fiddling around with the code here, but thought I'd ask here to see if I'm doing something dumb.
thanks,
sam
I have a user control that looks like this:
Code: Select all
public partial class VoiceViewSession : UserControl
{
public VoiceViewSession()
{
InitializeComponent();
}
private static readonly DependencyProperty _labelBackgroundProperty =
DependencyProperty.Register("SessionLabelBackground", typeof(Brush), typeof(VoiceViewSession), new PropertyMetadata(null));
public Brush SessionLabelBackground
{
get { return (Brush)GetValue(_labelBackgroundProperty); }
set { SetValue(_labelBackgroundProperty, value); }
}
private static readonly DependencyProperty _labelTextProperty =
DependencyProperty.Register("SessionLabelText", typeof(string), typeof(VoiceViewSession), new PropertyMetadata(null));
public string SessionLabelText
{
get { return (string)GetValue(_labelTextProperty); }
set { SetValue(_labelTextProperty, value); }
}
#if NOESIS
private void InitializeComponent()
{
NoesisUnity.LoadComponent(this);
}
#endif
}
I have a xaml using a custom control:
Code: Select all
<local:VoiceViewSession DataContext="{Binding Voice.SessionParty}" SessionLabelBackground="Purple" SessionLabelText="{noesis:Loc Text.InGame.Voice.Channel.Party}"/>
Code: Select all
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (!(serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget provideValueTarget))
{
return null;
}
DependencyObject dependencyObject = (DependencyObject)provideValueTarget.TargetObject;
DependencyProperty targetProperty = (DependencyProperty)provideValueTarget.TargetProperty; // <==== Exception being thrown here
LocMonitor locMonitor = (LocMonitor)dependencyObject.GetValue(MonitorProperty);
if (locMonitor == null)
{
locMonitor = new LocMonitor(dependencyObject);
dependencyObject.SetValue(MonitorProperty, locMonitor);
}
return locMonitor.AddDependencyProperty(targetProperty, _resourceKey);
}
Code: Select all
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast object of type 'System.Reflection.RuntimePropertyInfo' to type 'System.Windows.DependencyProperty'.
Source=Noesis.GUI.Extensions
StackTrace:
at NoesisGUIExtensions.LocExtension.ProvideValue(IServiceProvider serviceProvider) in NoesisGUIExtensions\LocExtension.cs:line 46
thanks,
sam