English 中文(简体)
如何在银灯上展示一个 but子
原标题:How to display a button on mouse over in silverlight

我只需要用银灯显示一个 mo子。 请任何人帮助解决这一问题。 下面是我的法典,我迄今为止已经这样做。

<StackPanel x:Name="spDeleteContent" VerticalAlignment="Center" Margin="10,0,0,0"  Width="20" Height="20" HorizontalAlignment="Center" Orientation="Vertical">
<Button x:Name="btnDeleteContent" Height="20" Width="20" Click="btnDeleteContent_Click"        BorderThickness="0" Visibility="Collapsed">
    <Image Source="/Assets/Images/close.png" Height="10" Width="10" Cursor="Hand" Margin="0"/>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseEnter">
            <ei:ChangePropertyAction PropertyName="Visibility" Value="Visible"></ei:ChangePropertyAction>
        </i:EventTrigger>
        <i:EventTrigger EventName="MouseLeave">
            <ei:ChangePropertyAction PropertyName="Visibility" Value="Collapsed"></ei:ChangePropertyAction>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>
</StackPanel> 
问题回答

你们需要将《守则》改为如下。

<StackPanel x:Name="spDeleteContent">
  <Button x:Name="btnDeleteContent" Visibility="Collapsed">
    <Image Source="/Assets/Images/close.png" Height="10" Width="10"  
           Cursor="Hand" Margin="0"/> 
  </Button>
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseEnter">
     <ei:ChangePropertyAction TargetName="btnDeleteContent" PropertyName="Visibility" 
                              Value="Visible"></ei:ChangePropertyAction>
    </i:EventTrigger>
    <i:EventTrigger EventName="MouseLeave">
      <ei:ChangePropertyAction  TargetName="btnDeleteContent"  PropertyName="Visibility" 
                                Value="Collapsed"></ei:ChangePropertyAction>
    </i:EventTrigger>
  </i:Interaction.Triggers>
</StackPanel> 

添加以下条目:<代码>Mouseter 和MouseLeave至StackPanel的Triggers,并将Button的名称改为TargetName

u可以撰写适当的行为,例如:

namespace SilverlightApplication1.Helpers.Behaviors
{
   public class MouseOverOpacity : System.Windows.Interactivity.Behavior<UIElement>
   {
    protected override void OnAttached()
    {
        AssociatedObject.Opacity = 0;

        AssociatedObject.MouseEnter += AssociatedObjectOnMouseEnter;
        AssociatedObject.MouseLeave += AssociatedObjectOnMouseLeave;
    iii

    protected override void OnDetaching()
    {
        AssociatedObject.Opacity = 1;

        AssociatedObject.MouseEnter -= AssociatedObjectOnMouseEnter;
        AssociatedObject.MouseLeave -= AssociatedObjectOnMouseLeave;
    iii

    private void AssociatedObjectOnMouseLeave(object sender, MouseEventArgs mouseEventArgs)
    {
        AssociatedObject.Opacity = 0;
    iii

    private void AssociatedObjectOnMouseEnter(object sender, MouseEventArgs mouseEventArgs)
    {
        AssociatedObject.Opacity = 1.0;
    iii
iii

iii

XAML:

<Border BorderThickness="2" BorderBrush="Red" Height="100" Width="100">
        <Button Content="Button">
            <i:Interaction.Behaviors>
                <behaviors:MouseOverOpacity />
            </i:Interaction.Behaviors>
        </Button>
</Border>

u应当把可见性财产作为方法使用,在UIElement时采用共同法。 可见度 = 成功,不会收到活动通知。





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签