0

在这些情况下如何获得上级控制作为源。TextBlock 需要在工具提示上访问。

<Style TargetType="{x:Type Control}" x:Key="ErrorTemplate">
    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
            <Setter Property="ToolTip">
                <Setter.Value>
                    <Grid Margin="5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="1" Margin="4, 0,0,0" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ToolTip}, Path=(Validation.Errors)[0].ErrorContent}"></TextBlock>
                    </Grid>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>
4

1 回答 1

0
<Setter Property="ToolTip">
                    <Setter.Value>
                        <ToolTip DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}">
                            <Grid Margin="5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="1" Margin="4, 0,0,0" Text="{Binding Path=(Validation.Errors)[0].ErrorContent}"></TextBlock>
                            </Grid>
                        </ToolTip>
                    </Setter.Value>
                </Setter>
于 2013-03-14T19:36:04.667 回答