2

我在单独的 xaml 文件中有自定义注释,我想使用来自选定图表主题的画笔。我有两点:

  1. 我正在尝试按如下方式访问 TextAnnotationForeground Brush(此处使用 SciChart 论坛中的示例):

    <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

我怎么能做到?

  1. 我需要为我的一个自定义注释再定义一个画笔,并且这个画笔应该根据所选主题进行更改。那么我可以在自定义主题 ResourceDictionary 中定义这个画笔并像第 1 点一样使用它吗?
4

1 回答 1

0

SciChart 的ThemeBinding MarkupExtension旨在获取应用到 DependencyObject 的当前主题,并获取由提供的字符串名称键入的资源,例如

 <TextBlock Foreground="{s:ThemeBinding TickTextBrush}"/> 

方法

获取应用于此 Textblock 或从上面继承的 ThemeManager.Theme 值,然后从该主题获取名为 TickTextBrush 的资源并将其应用于 TextBlock.Foreground

在 SciChart WPF 的 ThemeColorProvider 中有一个Themable 键的列表。

所以你可以直接使用我们的 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>

如果...这就是您想要做的(从主题中取出画笔并在您的应用程序的其他地方使用)。

于 2018-06-26T15:28:55.360 回答