Max*_*Max 2 eventtrigger windows-runtime windows-phone-8.1
我在带有caliburn的Windows Phone 8上开发了应用程序.在我的一个页面上,我在datatemplate中有一个按钮,我在鼠标点击时设置了触发器:
<DataTemplate>
<Button>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro1:ActionMessage MethodName="GoToPage">
<micro1:Parameter Value="{Binding Path=PageId}" />
</micro1:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBlock Text="{Binding Path=PageDescription}" TextWrapping="Wrap"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Button>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
它工作正常.现在我已经在Windows Phone 8.1(winrt)上创建了新的应用程序,但是使用相同的代码我在触发器上出错了.我怎么能在wp 8.1上做到这一点?我找到了winrttriggers.codeplex.com,但它与wp 8.1平台不兼容.
非常感谢!
编辑1:
使用您的代码,我的视图不会触发命令.我现在有:
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:InvokeCommandAction Command="{Binding OpenPageCommand}" CommandParameter="{Binding Path=PageId}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
Run Code Online (Sandbox Code Playgroud)
我的命令是委托命令:
public class DelegateCommand<T> : ICommand
{
private readonly Func<T, bool> _canExecuteMethod;
private readonly Action<T> _executeMethod;
#region Constructors
public DelegateCommand(Action<T> executeMethod)
: this(executeMethod, null)
{
}
public DelegateCommand(Action<T> executeMethod, Func<T, bool> canExecuteMethod)
{
_executeMethod = executeMethod;
_canExecuteMethod = canExecuteMethod;
}
#endregion Constructors
#region ICommand Members
public event EventHandler CanExecuteChanged;
bool ICommand.CanExecute(object parameter)
{
try
{
return CanExecute((T)parameter);
}
catch { return false; }
}
void ICommand.Execute(object parameter)
{
Execute((T)parameter);
}
#endregion ICommand Members
#region Public Methods
public bool CanExecute(T parameter)
{
return ((_canExecuteMethod == null) || _canExecuteMethod(parameter));
}
public void Execute(T parameter)
{
if (_executeMethod != null)
{
_executeMethod(parameter);
}
}
public void RaiseCanExecuteChanged()
{
OnCanExecuteChanged(EventArgs.Empty);
}
#endregion Public Methods
#region Protected Methods
protected virtual void OnCanExecuteChanged(EventArgs e)
{
var handler = CanExecuteChanged;
if (handler != null)
{
handler(this, e);
}
}
#endregion Protected Methods
}
Run Code Online (Sandbox Code Playgroud)
在我的视图模型中,我有:
public ICommand OpenPageCommand { get; set; }
Run Code Online (Sandbox Code Playgroud)
在构造函数上:
OpenPageCommand = new DelegateCommand<Guid>(GoToPage);
Run Code Online (Sandbox Code Playgroud)
我的方法是:
public void GoToPage(Guid pageId)
{ .....
Run Code Online (Sandbox Code Playgroud)
但它不起作用.任何的想法?
非常感谢!
您应该可以使用Behaviors SDK执行此操作.包含此命名空间:
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
Run Code Online (Sandbox Code Playgroud)
而且你应该能够触发这样的命令:
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:InvokeCommandAction Command="{Binding GoToPage}" CommandParameter="{Binding Path=PageId}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1365 次 |
| 最近记录: |