wpf InteractionRequestTrigger 不受支持

ilikeff8 2017-05-25 11:15:19
只是想在vm里弹一个对话框,然后ok,cancel后在vm里再做点事情, 按网上的例子

vm中

public InteractionRequest<Confirmation> ShowMessageBoxRequest { get; set; }

//MessageBox.Show("请选择设备");
ShowMessageBoxRequest.Raise(new Confirmation() { Title = "提示", Content = "请选择设备" }, (Confirmed) => { return; });


xaml中

xmlns:prism="http://www.codeplex.com/prism"

<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding ShowMessageBoxRequest, Mode=OneWay}">
<prism:PopupChildWindowAction ContentTemplate="{StaticResource ConfirmWindowTemplate}"/>
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>


但提示
程序集"Microsoft.Practices.Prism.Interactivity"中的类型"InteractionRequestTrigger"是利用旧版本的Blend SDK构建的,并且在Windows Presentation Framework 4 项目中不受支持
以及
命名空间 "http://www.codeplex.com/prism" 中不存在"PopupChildWindowAction"名称

那是要怎么写了
...全文
293 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuggzu 2017-05-25
  • 打赏
  • 举报
回复
引用:
- Microsoft.Expression.Interactions.dll
- System.Windows.Interactivity.dll
用法,百度
ilikeff8 2017-05-25
  • 打赏
  • 举报
回复
不想使用messagebox的okcancel,但要符合mvvm,这代码也太复杂了,而且关键还不对
ilikeff8 2017-05-25
  • 打赏
  • 举报
回复
引用 2 楼 xuggzu 的回复:
引用:
- Microsoft.Expression.Interactions.dll
- System.Windows.Interactivity.dll
用法,百度


1 命名空间 "http://www.codeplex.com/prism" 中不存在"PopupChildWindowAction"名称

是引用的dll的版本问题。我偷懒直接搜索使用了nuget上的提供的2个dll,可能是4.0的?


而工程的framework是4.5的
直接引用本机的blend 2017下的这2个dll就不会提示错误了

2 程序集"Microsoft.Practices.Prism.Interactivity"中的类型"InteractionRequestTrigger"是利用旧版本的Blend SDK构建的,并且在Windows Presentation Framework 4 项目中不受支持
然后这个提示可以无视,运行也不会出错

<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding ShowOKMessageBoxRequest}">
<ta:ShowOKMessageBoxTriggerAction/>
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>



public class ShowOKMessageBoxTriggerAction : TriggerAction<FrameworkElement>
{
protected override void Invoke(object parameter)
{
InteractionRequestedEventArgs interactionRequestedEventArgs = parameter as InteractionRequestedEventArgs;

if (interactionRequestedEventArgs != null)
{
Confirmation confirmation = interactionRequestedEventArgs.Context as Confirmation;

if (confirmation != null)
{
MessageBoxContent messageBoxContent = confirmation.Content as MessageBoxContent;

if (messageBoxContent != null)
{
MessageBox.Show(App.Current.MainWindow, messageBoxContent.content, confirmation.Title, MessageBoxButton.OK, messageBoxContent.messageBoxImage);
confirmation.Confirmed = true;

interactionRequestedEventArgs.Callback?.Invoke();
}
}
}
}
}


vm:

public InteractionRequest<Confirmation> ShowOKMessageBoxRequest { get; set; }

void InvokeShowOKMessageBoxRequest(string content, MessageBoxImage messageBoxImage)
{
ShowOKMessageBoxRequest.Raise(new Confirmation()
{
Title = "提示",
Content = new MessageBoxContent()
{
content = content,
messageBoxImage = messageBoxImage
}
});
}

public ICommand AppendUSBCAN2Command
{
get
{
return new DelegateCommand(() =>
{
if (CurrentSerial == null)
{
InvokeShowOKMessageBoxRequest("请选择设备", MessageBoxImage.Error);
return;
}
if (CurrentChannel_USBCAN2 == null)
{
InvokeShowOKMessageBoxRequest("请选择设通道", MessageBoxImage.Error);
return;
}

ControllerParam controllerParam = hardwareHelper.CreateDefaultParam_USBCAN2();

controllerParam.Serial = CurrentSerial;
controllerParam.Channel = CurrentChannel_USBCAN2.ID; // 1 - 通道1,2 - 通道2
hardwareHelper.AddController(controllerParam);
ControllerParamList = new ObservableCollection<ControllerParam>(hardwareHelper.ControllerParamList);
});
}
}



110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧