I am trying to tweak a style for an Infragistics DataRecordCellArea
for a XamDataGrid
to be largely based on the currently assigned style (via ThemeManager, but potentially on a parent element). Normally, if the theme were being applied in the same way as the system themes, I would do this using something like:
<!-- with xmlns:idp="http://infragistics.com/DataPresenter" -->
<Style
TargetType="{x:Type idp:DataRecordCellArea}"
BasedOn={StaticResource {x:Type idp:DataRecordCellArea}}
>
<!-- Style overrides -->
</Style>
with the style being injected as a resource on the XamDataGrid
, in the hope that the implicit style would be picked up based on the BasedOn
attribute. However, this isn't what's happening: using this approach, I get a XamlParseException
related to StaticResource
being unable to find the resource - i.e. there is no style to base things on.
"Great", you might think, "Just get rid of the based on and it'll work." This would be true except that doing so with an empty style clearly DOES affect the control's appearance as a deviation from what the theme provides.
My intended solution is a custom MarkupExtension that takes a named FrameworkElement
and a target type and attempts to find the implicit style that WOULD be in use were I to create an instance of the target type as a child of the context-providing object. If that turns out to be the default style (or even a null value), then so be it. This should be safe for sealing when the style starts to be used, too, because I do not need to respond to changes in context, just get the value at the point when the style is constructed. I think.
However, what I can't work out is HOW to retrieve the IMPLICIT style for an element when no explicit value is found for the actual style property. Finding the default style seems easy enough, but since there is no context providable to the Application.Current.FindResource()
method, I am convinced this will be the equivalent of leaving the BasedOn
attribute blank. Conversely, I expect to get false nulls if I simply get var implicit = Context.Resources.Contains(TargetType) ? Context.Resources[TargetType] : null;
, then I expect to only capture styles that are explicit members of that ResourceDictionary
and its collection of MergedDictionaries
.
There is a possibility of a further complication, too: namely the possibility that the style I actually want to replace may NOT be keyed only with the type. For instance, imagine that the theme may use the same object for multiple purposes, and each of those purposes has a specific key name, with the style then assigned during the ControlTemplate
being configured for the parent object, i.e.
<Style TargetType={XamDataGridOrSomeUnknownChildOfXamDataGrid}>
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ControlTemplate.Resources>
<Style TargetType="{TheTypeICareAbout}" x:Key="SomeActualKeyedValue" BasedOn="{StaticResource SomeThemeStyleOrKeyToTheDefaultOne}">
<!-- Style definition -->
</Style>
</ControlTemplate.Resources>
...
<TheTypeICareAbout Style="{StaticResource SomeActualKeyedValue}" />
...
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
For the time being, I am hoping that this is NOT what is happening, but there is at least some evidence that indicates it might be. If anyone knows of a way to hook onto and override THAT style when the ControlTemplate
is rendered, this would also answer my problem - possibly better than finding the implicit style (because then I'm not actually overriding an implicit style).