1

我在 WPF 中创建了一个 UserControl,并且 UserControl 的工作原理是当用户将鼠标移到控件上时,它的子控件应该被删除,但我似乎没有找到 Children 属性或类似的东西..

XAML 在这里:

<UserControl x:Class="myTextBox"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         Name="thisTextBox"
         mc:Ignorable="d" d:DesignWidth="300" Height="57"     MouseEnter="UserControl_MouseEnter_1" MouseLeave="UserControl_MouseLeave_1">
<TextBlock Name="TypeText" TextWrapping="NoWrap" Text="" />
</UserControl>

在代码中我需要做这样的事情来让 TextBlock 消失:

private void UserControl_MouseEnter_1(object sender, MouseEventArgs e)
{
     Children.Clear(); // There is no such thing as children here!!!
}
4

1 回答 1

4

UserControl 的“子元素”包含在Content属性中。您可以将其设置为null以删除内容。

private void UserControl_MouseEnter_1(object sender, MouseEventArgs e)
{
    Content = null;
}
于 2013-02-20T21:09:49.307 回答