似乎我无法正确理解jQuery触发器('click')功能.
有人可以告诉我为什么这个简单的代码不起作用以及如何解决?
HTML:
<a id="bar" href="http://stackoverflow.com" target="_blank">Don't click me!</a>
<span id="foo">Click me!</span>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
jQuery('#foo').on('click', function(){
jQuery('#bar').trigger('click');
});
Run Code Online (Sandbox Code Playgroud)
演示:FIDDLE
我想要的是能够点击#foo(运行良好)并模拟#bar上的点击(完全忽略,没有任何错误消息).也试过jQuery(document).ready(function(){...})
但没有成功.
我希望能够使用EventTrigger设置属性,这有很多问题.
1)EventTriggers仅支持Actions,因此我必须使用storyBoard来设置我的属性.
2)一旦我使用故事板,我有两个选择:
在下面的示例中,我想在单击按钮时将IsChecked属性设置为False,并且我希望用户能够更改IsChecked和/或我希望能够更改代码中的属性.
例:
<EventTrigger
SourceName="myButton"
RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetName="myCheckBox"
Storyboard.TargetProperty="IsChecked"
FillBehavior="Stop">
<DiscreteBooleanKeyFrame
KeyTime="00:00:00"
Value="False" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
Run Code Online (Sandbox Code Playgroud)
我意识到在故事板完成后我可以使用"已完成"事件将值设置为False.但是,在这种情况下,我想在XAML中包含逻辑,因为此逻辑将用于自定义控件,并且仅特定于UI.
我有两个控件,一个TextBlock和一个PopUp.当用户在文本块上单击(MouseDown)时,我想显示弹出窗口.我认为我可以在Popup上使用EventTrigger执行此操作,但我不能在EventTrigger中使用setter,我只能启动故事板.我想在XAML中严格执行此操作,因为这两个控件都在模板中,我不知道如何在代码中找到弹出窗口.
这是概念上我想做的,但不能,因为你不能把一个setter放在EventTrigger中(就像你可以使用DataTrigger):
<TextBlock x:Name="CCD">Some text</TextBlock>
<Popup>
<Popup.Style>
<Style>
<Style.Triggers>
<EventTrigger SourceName="CCD" RoutedEvent="MouseDown">
<Setter Property="Popup.IsOpen" Value="True" />
</EventTrigger>
</Style.Triggers>
</Style>
</Popup.Style>
...
Run Code Online (Sandbox Code Playgroud)
当事件发生在不同的控件上时,在XAML中严格显示弹出窗口的最佳方法是什么?
这是场景:
我有以下用户控件,想法是它的视图模型应该能够向视图发出信号,它需要"激活发光",从而播放故事板.
<UserControl x:Class="View.UnitView" ... >
...
<Storyboard x:Key="ActivateGlow">
...
</Storyboard>
...
<!-- INVALID BINDING! Not Dependancy Object-->
<EventTrigger RoutedEvent="{Binding OnActivateGlow}">
<BeginStoryboard Storyboard="{StaticResource ActivateGlow}"/>
</EventTrigger>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
在UnitView的代码隐藏中,我有:
public event EventHandler ActivateGlow;
Run Code Online (Sandbox Code Playgroud)
并且在MVVM中非常正常,我为UnitViewModel提供了以下DataTemplate:
<DataTemplate DataType="{x:Type vm:UnitViewModel}">
<vw:UnitView d:DesignWidth="150" d:DesignHeight="100" />
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
最后一个问题是,我如何设置一些东西,以便viewmodel可以触发OnActivateGlow事件?
有没有办法Focus
使用WPF从一个控件设置到另一个控件Trigger
?
如下例所示:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Name="txtName"></TextBox>
<TextBox Grid.Row="1" Name="txtAddress"></TextBox>
<Button Grid.Row="2" Content="Finish">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<!-- Insert cool code here-->
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
</Page>
Run Code Online (Sandbox Code Playgroud)
有没有办法EventTrigger
把重点放在textBox"txtName"上?
我试图找到使用严格的MVVM做这样的事情的方法.如果这是不应该通过XAML(在MVVM中)完成的,那么这很好.但我希望看到一些文档,说明它如何适合在XAML之外的MVVM模式.
以下代码工作正常.
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:.8" Storyboard.TargetProperty="Left" From="1920" To="0" AccelerationRatio=".1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
Run Code Online (Sandbox Code Playgroud)
但在这方面From
,To
价值观是静态的.我需要根据系统分辨率动态传递值.所以我需要在后面的代码中创建它.有可能吗?
如何将其转换为代码隐藏?
我试图实现悬停事件但是onMouseLeave并不总是在离开元素时触发,特别是在快速移动光标元素时.我试过Chrome,Firefox和Internet Explorer,但在每个浏览器中都出现了同样的问题.
我的代码:
import React from 'react';
import Autolinker from 'autolinker';
import DateTime from './DateTime.jsx'
class Comment extends React.Component{
constructor(props){
super(props);
this.handleOnMouseOver = this.handleOnMouseOver.bind(this);
this.handleOnMouseOut = this.handleOnMouseOut.bind(this);
this.state = {
hovering: false
};
}
render(){
return <li className="media comment" onMouseEnter={this.handleOnMouseOver} onMouseLeave={this.handleOnMouseOut}>
<div className="image">
<img src={this.props.activity.user.avatar.small_url} width="42" height="42" />
</div>
<div className="body">
{this.state.hovering ? null : <time className="pull-right"><DateTime timeInMiliseconds={this.props.activity.published_at} byDay={true}/></time>}
<p>
<strong>
<span>{this.props.activity.user.full_name}</span>
{this.state.hovering ? <span className="edit-comment">Edit</span> : null}
</strong>
</p>
</div>
</li>;
}
handleOnMouseOver(event){
event.preventDefault();
this.setState({hovering:true});
}
handleOnMouseOut(event){
event.preventDefault();
this.setState({hovering:false}); …
Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中淡入/淡出一个窗口.
淡入时发生Window.Loaded
,我想在关闭(Window.Closed
或Window.Closing
)时淡出.淡入效果完美,但Window.Closing
不允许RoutedEvent
财产价值.
我RoutedEvent
应该用什么关闭?
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Window.Closing">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:2" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
Run Code Online (Sandbox Code Playgroud)
我收到错误,值'Window.Closing'无法分配给属性'RoutedEvent'.无效的活动名称.
我想在a中按下ENTER时调用一个命令TextBox
.考虑以下XAML:
<UserControl
...
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
...>
...
<TextBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
<i:InvokeCommandAction Command="{Binding MyCommand}"
CommandParameter="{Binding Text}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
...
</UserControl>
Run Code Online (Sandbox Code Playgroud)
并且MyCommand如下:
public ICommand MyCommand {
get { return new DelegateCommand<string>(MyCommandExecute); }
}
private void MyCommandExecute(string s) { ... }
Run Code Online (Sandbox Code Playgroud)
使用上面的命令,我会在每次按键时调用我的命令.如何将命令限制为仅在按下ENTER键时调用?
我理解使用Expression Blend我可以使用条件,但这些似乎仅限于元素,不能考虑事件参数.
我也遇到过SLEX,它提供了自己的InvokeCommandAction
实现,它构建在Systems.Windows.Interactivity
实现之上,可以满足我的需求.另一个考虑是编写我自己的触发器,但我希望有一种方法可以在不使用外部工具包的情况下完成.
我正在尝试将数据从我的应用程序共享到其他应用程序,如短信或任何其他应用程序.我有一个应用程序,我需要发送或共享一些数据到应用程序,如短信或fb信使.通过此链接,我可以打开应用程序并使用以下代码将数据添加到文本框中:
Intent sendIntent = new Intent();
sendIntent.setPackage("com.sms or fb");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
Run Code Online (Sandbox Code Playgroud)
使用这个应用程序,我可以打开其他应用程序,并在文本区域中添加值我的问题是有什么办法,我可以触发点击或发送事件发送自动消息到其他应用程序,如短信Facebook.如果是这样,我如何看到谷歌应用程序,我用我的声音发送给我的whatsapp联系人,所以这种方法是谷歌应用程序可以使用我的声音发送消息和触发事件.我的问题是如何使用我的Android代码触发事件发送.如果root系统在那里我也可以使用它.
没有一个答案甚至接近我想要解决的问题,没有答案值得赏心悦目.
eventtrigger ×10
wpf ×6
c# ×3
xaml ×3
animation ×2
events ×2
javascript ×2
mvvm ×2
triggers ×2
.net ×1
android ×1
focus ×1
hover ×1
html ×1
jquery ×1
popup ×1
reactjs ×1
routedevent ×1
silverlight ×1