<StackPanel>
<TextBox Text="" x:Name="input"/>
<TextBox Text="" x:Name="input2"/>
<Button Content="Click" ToolTip="123">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding OnAdd}" CommandParameter="1">
</i:InvokeCommandAction>
</i:EventTrigger>
<ei:DataTrigger Binding="{Binding Text, ElementName=input}" Comparison="Equal" Value="123" >
<!-- 在这里能否触发他的Click事件呢? -->
</ei:DataTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>也就是当input的Text为123的时候,触发Button的Click事件谢谢
解决方案 »
- 用WebBrowser 百度自动登录,密码不能赋值,求助
- 怎么验证数据库里的信息
- 安装程序 如何将.netframework 和程序打包成一个exe
- 可以用struct来写一个链表吗?
- asp.net onmouseover的问题
- 求C#实现对Excel的复杂操作的文章或代码!最好效率高一些的
- 求代码xml
- Business层和UI层通信问题
- 怎样用程序实现(c#)excel导入远程的sqlserver数据库?哪个大哥帮忙一下?
- 关于C#中Console.WriteLine语句输出格式的问题
- |ZYCWPF| 如何通过.NET来实现我对一个视频的RTSP直播呢? 谢谢
- 请高手指点一下这个函数为什么总出错
{
// 触发btn1的Click事件
btn1.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
}前台调用: <StackPanel>
<TextBox Text="" x:Name="input"/>
<TextBox Text="" x:Name="input2"/>
<Button Content="Click" ToolTip="123" Name="btn1"><!-- 起个名字btn1 -->
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding OnAdd}" CommandParameter="1" />
</i:EventTrigger>
<ei:DataTrigger Binding="{Binding Text, ElementName=input}" Comparison="Equal" Value="123" >
<ei:CallMethodAction TargetObject="{Binding}" MethodName="RaiseClick" />
</ei:DataTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
using System.Windows.Interactivity;namespace WpfApp1
{
public class RaiseEventAction : TargetedTriggerAction<UIElement>
{
public static readonly DependencyProperty EventProperty = DependencyProperty.RegisterAttached("Event", typeof(RoutedEvent), typeof(RaiseEventAction), new FrameworkPropertyMetadata(null)); public RoutedEvent Event
{
get { return (RoutedEvent) GetValue(EventProperty); }
set { SetValue(EventProperty, value); }
} protected override void Invoke(object parameter)
{
if (Target != null && Event != null)
Target.RaiseEvent(new RoutedEventArgs(Event));
}
}
}前台可以这样调用:<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:WpfApp1"
Title="MainWindow" Height="350" Width="525"
Name="MyWindow"
>
<StackPanel>
<TextBox Text="" x:Name="input"/>
<TextBox Text="" x:Name="input2"/>
<Button Content="Click" ToolTip="123" Name="btn1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding OnAdd}" CommandParameter="1" /><!-- 改成你的点击事件处理方法 -->
</i:EventTrigger>
<ei:DataTrigger Binding="{Binding Text, ElementName=input}" Comparison="Equal" Value="123" >
<local:RaiseEventAction TargetObject="{Binding ElementName=btn1}" Event="{x:Static Button.ClickEvent}" />
</ei:DataTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
</Window>