我正在尝试在ToolTip. 下面是 Xaml 代码和ToolTip.
问题是如果我使用 windowsFormsHost 面板不会改变颜色,感觉就像ToolTip不知道它在那里。
我做对了吗?
(如果我能够更改颜色,那么我将使用它来显示相机的 liveFeed)
当我点击按钮时,它就在ToolTip那里,但它仍然是基本的。
如果我没有 Windows 窗体主机并使用 aStackPanel那么它可以工作。但我需要使用Panel.
xml:
<Grid>
<Button Width="100" Height="100">
        <Button.ToolTip>
            <Controls:MyToolTip Height="500" Width="550">
                    <WindowsFormsHost x:Name="wrapper" Margin="0,0,0,0" Background="{x:Null}">
                        <wf:Panel x:Name="previewScreen" BackColor="Purple" Size="200,200" >
                        </wf:Panel>
                    </WindowsFormsHost>
            </Controls:MyToolTip>
        </Button.ToolTip>
  </Button>
  </Grid>
C# :
public class MyToolTip : ToolTip
{
    protected override void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate)
    {
        if (newTemplate != null)
        {
            this.Visibility = Visibility.Collapsed;
            this.IsOpen = true;
            Popup popup = GetPopupFromVisualChild(this);
            if (popup != null) popup.AllowsTransparency = false;
            this.IsOpen = false;
            this.Visibility = Visibility.Visible;
        }
    }
    private static Popup GetPopupFromVisualChild(Visual child)
    {
        Visual parent = child;
        FrameworkElement visualRoot = null;
        while (parent != null)
        {
            visualRoot = parent as FrameworkElement;
            parent = VisualTreeHelper.GetParent(parent) as Visual;
        }
        Popup popup = null;
        if (visualRoot != null)
        {
            popup = visualRoot.Parent as Popup;
        }
        return popup;
    }
}
感谢您的时间和帮助。