我遇到的问题的简单案例代码:
<Window x:Class="WFHTooltipEnableTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<WindowsFormsHost Name="HostControl">
<wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>
</WindowsFormsHost>
<Button Content="Toggle" Grid.Row="1" Click="Button_Click"></Button>
</Grid>
</Window>
using System.Windows;
using System.Windows.Controls;
namespace WFHTooltipEnableTest
{
public partial class MainWindow : Window
{
bool enabled = true;
public MainWindow() {}
private void Button_Click(object sender, RoutedEventArgs e)
{
enabled = !enabled;
ToolTipService.SetIsEnabled(this.HostControl, enabled);
}
}
}
该按钮将切换传递给 SetIsEnabled 的值。当为 false 时,托管在 windows 窗体主机控件中的东西将被禁用。
似乎无法为这种行为找到任何解释。