用户控件项内标签上的单击事件

发布于 2024-10-08 14:11:38 字数 3250 浏览 0 评论 0原文

您好,我正在尝试在用户控件内的文本块上创建单击文本块事件, 使用按钮很简单,使用主窗口上的 Buttonbase 属性,但在这里 我不知道该怎么做,我会向你展示我的代码: 这是我的用户控件:

 <Border BorderBrush="Purple" BorderThickness="3" CornerRadius="3" Margin="3" >
    <DockPanel>
        <Grid DockPanel.Dock="Left">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="120"/>
            </Grid.ColumnDefinitions>
            <Label Foreground="Blue">Message Number:</Label>
            <Label Foreground="Blue" Grid.Row="1">Title:</Label>
            <Label Foreground="Blue" Grid.Row="2">Message Date:</Label>
            <Label Foreground="Blue" Grid.Row="3">Contact Mail:</Label>
            <Label Foreground="Blue" Grid.Row="4">Message Type:</Label>
            <Label Foreground="Blue" Grid.Row="5">Message Details:</Label>
            <Label x:Name="lblMessageNum" Grid.Column="1"></Label>
            <Label x:Name="lblTitle" Grid.Column="1" Grid.Row="1"></Label>
            <Label x:Name="lblMessageDate" Grid.Column="1" Grid.Row="2"></Label>
            <Label x:Name="lblContactMail" Grid.Column="1" Grid.Row="3"></Label>
            <Label x:Name="lblMessageType" Grid.Column="1" Grid.Row="4"></Label>
            <Label x:Name="lblMessageDetails" Grid.Column="1" Grid.Row="5"></Label>
        </Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock  Margin="23,0,0,0" x:Name="tbkRemove">
                <Underline>Remove Message</Underline>
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Setter Property= "Foreground" Value="Blue"/>
                        <Style.Triggers>
                            <Trigger Property ="IsMouseOver" Value="True">
                                <Setter Property= "Foreground" Value="Red"/>
                            </Trigger>
                       </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
            <Border Grid.Row="1"  BorderBrush="Purple" CornerRadius="3" BorderThickness="3" Margin="23,10,6,0">
                <Image x:Name="ImgPic" Width="102" Height="110"></Image>
            </Border>


        </Grid>
    </DockPanel>
</Border>

在这个用户控件中,我得到了 tbkRemove 文本块,它应该有一个事件将其自身(所有用户控件)从主窗口中删除,因此单击事件的代码应该位于主窗口上,但我该如何制作这样的事件 预先感谢您的帮助

hello i am trying to create a click textblock event on a textblock inside a user control ,
with a button it is simple , using the buttonbase property on the main window but here
i am not sure what to do i will show you my code:
this is my user control:

 <Border BorderBrush="Purple" BorderThickness="3" CornerRadius="3" Margin="3" >
    <DockPanel>
        <Grid DockPanel.Dock="Left">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="120"/>
            </Grid.ColumnDefinitions>
            <Label Foreground="Blue">Message Number:</Label>
            <Label Foreground="Blue" Grid.Row="1">Title:</Label>
            <Label Foreground="Blue" Grid.Row="2">Message Date:</Label>
            <Label Foreground="Blue" Grid.Row="3">Contact Mail:</Label>
            <Label Foreground="Blue" Grid.Row="4">Message Type:</Label>
            <Label Foreground="Blue" Grid.Row="5">Message Details:</Label>
            <Label x:Name="lblMessageNum" Grid.Column="1"></Label>
            <Label x:Name="lblTitle" Grid.Column="1" Grid.Row="1"></Label>
            <Label x:Name="lblMessageDate" Grid.Column="1" Grid.Row="2"></Label>
            <Label x:Name="lblContactMail" Grid.Column="1" Grid.Row="3"></Label>
            <Label x:Name="lblMessageType" Grid.Column="1" Grid.Row="4"></Label>
            <Label x:Name="lblMessageDetails" Grid.Column="1" Grid.Row="5"></Label>
        </Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock  Margin="23,0,0,0" x:Name="tbkRemove">
                <Underline>Remove Message</Underline>
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Setter Property= "Foreground" Value="Blue"/>
                        <Style.Triggers>
                            <Trigger Property ="IsMouseOver" Value="True">
                                <Setter Property= "Foreground" Value="Red"/>
                            </Trigger>
                       </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
            <Border Grid.Row="1"  BorderBrush="Purple" CornerRadius="3" BorderThickness="3" Margin="23,10,6,0">
                <Image x:Name="ImgPic" Width="102" Height="110"></Image>
            </Border>


        </Grid>
    </DockPanel>
</Border>

inside this usercontrol i got tbkRemove textblock which should have an event to remove it self (the all user control) from the main window so the code of the click event should be on the main window but how can i make such an event
thanks in advance for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无边思念无边月 2024-10-15 14:11:38

我使用表达式混合器创建了一个看起来像文本块的新按钮,因此我可以使用 Buttonbase 将其冒泡。

i created a new button that looks like a textblock using expression blender so i can bubble it up using buttonbase .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文