【发布时间】:2017-10-23 11:54:56
【问题描述】:
对于这个问题,我来解释一下环境。
我在 XAML 中有一个 UserControl,我无法访问后面的代码,我必须在 XAML 部分中完成所有工作。我也无权访问 Window 代码。只有用户控件必须保存窗口位置。
问题是:我的关闭触发器从未触发(但此触发器可以在代码中进一步单击“取消”按钮时正常工作)
我无法访问我可以访问的唯一部分代码。 由于 userCommandBuilder,我不能将触发器放在资源之前。
触发器。
<UserControl
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
...otherstuff...
MinWidth="946" MinHeight="902" MaxWidth="946" MaxHeight="902">
<UserControl.Resources.../>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Close">
<i:InvokeCommandAction Command="{x:Static addin:AddInCommands.ExecuteCmdLine}" >
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource userCommandBuilder}" ConverterParameter="SRSAVEPOSITION -T {0} -L {1}">
<Binding RelativeSource="{RelativeSource AncestorType={x:Type Window}}" Path="Top" />
<Binding RelativeSource="{RelativeSource AncestorType={x:Type Window}}" Path="Left" />
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
我做错了什么? 如何解决?
取消按钮代码
<Button Margin="0,0,0,0" IsCancel="True" FontSize="13" FontFamily="Segoe UI">Cancel>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{x:Static addin:AddInCommands.ExecuteCmdLine}" >
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource userCommandBuilder}" ConverterParameter="SRSAVEPOSITION -T {0} -L {1}">
<Binding RelativeSource="{RelativeSource AncestorType={x:Type Window}}" Path="Top" />
<Binding RelativeSource="{RelativeSource AncestorType={x:Type Window}}" Path="Left" />
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
<i:InvokeCommandAction Command="ApplicationCommands.Close" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
【问题讨论】:
-
你有
Cancel的代码吗?所以我们可以比较。 -
是的,我明天会带着取消按钮代码回来。
-
已添加代码。与关闭事件没有什么不同。但是如果用户控件上不存在关闭事件或卸载事件,我不知道如何做到这一点:)
标签: c# wpf xaml triggers user-controls