How to declare a resource from a private inner class in WPF?
-
06-07-2019 - |
Question
I'm trying to declare a resource in a WPF UserControl, and I'd like the resource to be an instance of a private inner class. How do I do this?
XAML:
<UserControl ...>
<UserControl.Resources>
<local:MyConverter x:Key="MyConverter" />
</UserControl.Resources>
</UserControl>
Code Behind:
public partial class MyUserControl : UserControl
{
private class MyConverter : IValueConverter
{
// convertion code...
}
}
Solution
You can't do it if the class is private, you could make it internal instead
Regarding the declaration of an inner class in XAML, you should have a look at this discussion
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow