0

我有一个工具提示问题。我想将模板化工具提示添加到带有一些信息的按钮。

这里是带有工具提示的按钮,它的数据上下文绑定到某个视图模型:

<fluent:Button DataContext="{Binding NewConnections, Source={StaticResource Locator}}" Command="{Binding AddCloudStorageAccount}" Header="Add Account">
                        <fluent:Button.LargeIcon>
                            <Image Source="pack://application:,,,/Icons;component/UI/v1/add_account.png" Width="48"/>
                        </fluent:Button.LargeIcon>
                        <fluent:Button.ToolTip>
                            <ToolTip DataContext="{Binding UserInput.AddAccountsButtonInfo, Source={StaticResource Locator}}" Style="{StaticResource ButtonTooltip}"></ToolTip>
                        </fluent:Button.ToolTip>
                    </fluent:Button>

风格:

 <Style TargetType="ToolTip" x:Key="ButtonTooltip">
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <Border  Background="LightYellow" BorderThickness="0.5" BorderBrush="Maroon">
                    <StackPanel Orientation="Vertical" Margin="3">
                        <TextBlock x:Name="_txtText" Text="{Binding Title}"></TextBlock>
                        <TextBlock x:Name="_txtDescription" Margin="0 10 0 0" Text="{Binding Description}"></TextBlock>
                        <TextBlock x:Name="_txtHotKeyDescription" Margin="0 10 0 0" Text="{Binding HotKeyDescription}"></TextBlock>
                    </StackPanel>
                </Border>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

我设置了一些断点来查看是否访问了视图模型。没关系。但是根本没有访问像标题​​这样的属性,我只看到没有任何文本的空矩形

有人有什么想法吗?

4

1 回答 1

0

刚刚解决它(在边框中设置数据上下文)。也许有人会感兴趣:

<Style TargetType="ToolTip" x:Key="ButtonTooltip">
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <Border  Background="LightYellow" BorderThickness="0.5" BorderBrush="Maroon" DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ToolTip}}}">
                    <StackPanel Orientation="Vertical" Margin="3">
                        <TextBlock x:Name="_txtText" Text="{Binding Title}"></TextBlock>
                        <TextBlock x:Name="_txtDescription" Margin="0 10 0 0" Text="{Binding Description}"></TextBlock>
                        <TextBlock x:Name="_txtHotKeyDescription" Margin="0 10 0 0" Text="{Binding HotKeyDescription}"></TextBlock>
                    </StackPanel>
                </Border>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>
于 2013-08-13T09:51:08.610 回答