我在单独的xaml文件中具有自定义注释,我想使用所选图表主题中的画笔。 我有两点:
我正尝试按以下方式访问TextAnnotationForeground Brush(以SciChart论坛here中的示例为例):
<s:CustomAnnotation x:Class="Charts.SciCharts.MarkerAnnotation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
VerticalAnchorPoint="Top" HorizontalAnchorPoint="Center" Margin="0">
<s:CustomAnnotation.Template>
<ControlTemplate TargetType="s:CustomAnnotation">
<Border>
<Viewbox>
<StackPanel>
<Path Data="m 4 14 4 0 0 -8 3 0 -5 -5 -5 5 3 0 z" Fill="#571CB61C"
Stroke="#FF00B400" StrokeThickness="1" HorizontalAlignment="Center"/>
<Border Margin="5" Padding="5 0 5 2" BorderThickness="1" BorderBrush="#FF00B400"
Background="#571CB61C" CornerRadius="5" HorizontalAlignment="Center">
<TextBlock FontSize="12" Text="{Binding Label}" Foreground="{s:ThemeBinding TextAnnotationForeground}"/>
</Border>
</StackPanel>
</Viewbox>
</Border>
</ControlTemplate>
</s:CustomAnnotation.Template>
</s:CustomAnnotation>
在设计时和运行时都出现了错误:
Inner exception: Not a dependency object
我怎么做?
答案 0 :(得分:0)
SciChart的ThemeBinding MarkupExtension旨在将当前主题应用于DependencyObject,并获取由提供的字符串名称作为键的资源,例如
<TextBlock Foreground="{s:ThemeBinding TickTextBrush}"/>
表示
获取应用于此Textblock或从上方继承的ThemeManager.Theme值,然后从该主题获取名为TickTextBrush的资源,并将其应用于TextBlock.Foreground
有Themable keys in SciChart WPF's ThemeColorProvider here列表。
因此您可以直接使用我们的ThemeBinding。但是,如果您只想从字典中获取一个值,则最好这样做:
<Grid>
<Grid.Resources>
<ResourceDictionary>
<!-- Merged Dictionary is required for BasedOn attribute -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/SciChart.Charting;component/Themes/ExpressionDark.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<SolidColorBrush x:Key="ColorBrush" Color="StaticResource MountainLineColor"/>
</Grid.Resources>
</Grid>
如果...就是您想要做的(从主题中获取画笔,然后在应用程序中的其他位置使用)。