I wonder if XAML is somehow able to "deduce" the C# inheritance. Let me explain:
I have these two C# classes:
public class AStyleSelector: StyleSelector {
public Style aStyle { get; set; }
public override Style SelectStyle(object item, DependencyObject container)
{
//....
}
}
public class BStyleSelector : AStyleSelector{
public Style bStyle { get; set; }
public override Style SelectStyle(object item, DependencyObject container)
{
var tmp = aStyle; // this is null
//....
}
}
BStyleSelector inherits from AStyleSelector which inherits from StyleSelector. They both implement SelectStyle.
Then I have the next in a XAML file: Here I defined two styles:
<Style // to be used in both AStyleSelector and BStyleSelector
x:Key="StyleA"
//... some styles
</Style>
<Style // to be used only in BStyleSelector
x:Key="StyleB"
//... some styles
</Style>
Here I am binding to C# classes and pointing to the defined Styles:
<AStyleSelector //pointing to the above C# class
aStyle="{StaticResource StyleA}" />
<BStyleSelector //pointing to the above C# class"
bStyle="{StaticResource StyleB}" />
Now, the problem is, in the method SelectStyle from BStyleSelector, I cannot access the value of aStyle. It is returning null.
I know there is a quick fix (that works correctly) which is this:
<BStyleSelector
aStyle="{StaticResource StyleA}" // adding this line
bStyle="{StaticResource StyleB}" />
But I don't want to reference twice the StyleA. I was expecting that XAML would deduce it's value because BStyleSelector inherits it from AStyleSelector.
Is there some way to do this?
Thanks a lot in advance.