【发布时间】:2010-12-19 07:17:58
【问题描述】:
您好,我正在尝试在用户控件内的文本块上创建单击文本块事件, 使用按钮很简单,使用主窗口上的 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 文本块,它应该有一个事件来从主窗口中删除它自己(所有用户控件),所以点击事件的代码应该在主窗口上,但是我怎样才能制作这样的事件 提前感谢您的帮助
【问题讨论】:
-
我想我理解这个问题,但并不完全理解您希望如何处理这个问题。如果您可以为您谈到的 Button 示例添加一些示例代码,也许会有所帮助