1

我有这种情况:

我为自定义组件的工具提示定义了一种样式:

<Style x:Key="ToolTipPieChart" TargetType="{x:Type ToolTip}">
    <Setter Property="Opacity" Value=".95" />
    <Setter Property="Template">
        <Setter.Value>
            <!-- modify the tooltip control template to add a drop shadow-->
            <ControlTemplate TargetType="{x:Type ToolTip}">
                <Grid Background="Transparent" Margin="5" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                    <Rectangle Fill="White" Height="{TemplateBinding Height}" RadiusX="7.5" RadiusY="7.5">
                        <Rectangle.BitmapEffect>
                            <DropShadowBitmapEffect ShadowDepth="3"/>
                        </Rectangle.BitmapEffect>
                    </Rectangle>
                    <ContentPresenter Margin="5"  HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <!-- bind the stack panel datacontext to the tooltip data context -->
                <StackPanel Orientation="Horizontal"
                DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type ToolTip}}}">

                    <!-- navigate to the pie piece (which is the placement target of the tooltip) and obtain the percentage -->
                    <TextBlock FontSize="30" FontWeight="Bold" Margin="0,0,5,0"                        
                    DataContext="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ToolTip}}}"
                    Text="{Binding Path=Percentage, Converter={StaticResource formatter}, ConverterParameter='\{0:0%\}'}"/>

                    <StackPanel Orientation="Vertical">
                        <TextBlock FontWeight="Bold"  Text="{Binding Path=AFCDENTE}"/>
                        <!--<StackPanel Orientation="Horizontal">
                    <TextBlock Name="_txbEnte" Text="AFCDENTE"/>
                    <TextBlock Text=": "/>
                    <TextBlock Text="{Binding Path=AFCDENTE}"/>
                </StackPanel>-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbModGen" Text="Modgen"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=Modgen}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbAggAlter" Text="AggAlter"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=AggAlter}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbAggTolt" Text="AggTolt"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=AggTolt}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbModDis" Text="ModDis"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=ModDis}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbModPar" Text="ModPar"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=ModPar}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbCamPrior"  Text="CamPrior"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=CamPrior}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbCamCL" Text="CamCL"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=CamCL}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbCamMat" Text="CamMat"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=CamMat}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbModTTechP" Text="ModTTechP"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=ModTTechP}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Name="_txbModTRianL" Text="ModTRianL"/>
                            <TextBlock Text=": "/>
                            <TextBlock Text="{Binding Path=ModTRianL}"/>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

这是我的组件:

<PieChart:PieChartLayout HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0"
    x:Name="piePlotter" PlottedProperty="Totale" DisplayProperty="AFCDENTE" Margin="10">
    <PieChart:PieChartLayout.ColorSelector>
        <PieChart:IndexedColourSelector Brushes="{StaticResource brushes}"/>
    </PieChart:PieChartLayout.ColorSelector>
    <PieChart:PieChartLayout.ToolTip>
        <ToolTip Style="{StaticResource ToolTipPieChart}" />
    </PieChart:PieChartLayout.ToolTip>
</PieChart:PieChartLayout>

样式未应用。你认为为什么?我应该怎么办?

4

1 回答 1

1

如何定义ToolTip Style实际的内部指令PieChartLayout.Resources和全方位x:Key指令?:

<PieChart:PieChartLayout HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0"
    x:Name="piePlotter" PlottedProperty="Totale" DisplayProperty="AFCDENTE" Margin="10">
    <PieChart:PieChartLayout.Resources>
        <!-- Define your ToolTip Style here WITHOUT setting x:Key Directive -->
        <Style TargetType="{x:Type ToolTip}">
            ...
        </Style>
    </PieChart:PieChartLayout.Resources>
    <PieChart:PieChartLayout.ColorSelector>
        <PieChart:IndexedColourSelector Brushes="{StaticResource brushes}"/>
    </PieChart:PieChartLayout.ColorSelector>
    <PieChart:PieChartLayout.ToolTip>
        <ToolTip />
    </PieChart:PieChartLayout.ToolTip>
</PieChart:PieChartLayout>
于 2015-06-24T09:02:59.703 回答