gpt4 book ai didi

c# - CommandParameter 始终通过 ElementName 绑定(bind)传递 EventArgs,没有实际绑定(bind)值

转载 作者:行者123 更新时间:2023-12-03 10:35:49 32 4
gpt4 key购买 nike

因此,我想使用 Behavior SDK 将 Pivot 事件绑定(bind)到我的 View 模型。绑定(bind)看起来像这样:

<Pivot Grid.Row="1" x:Name="pvtMain"
ItemsSource="{Binding Items}"
HeaderTemplate="{StaticResource PivotHeaderTemplate}">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="PivotItemLoading">
<Core:InvokeCommandAction Command="{Binding LoadAdditionalData}"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>

</Pivot>

在 Viewmodel 中执行的操作如下所示:
private void _CommandLoadAdditionalData(object parameter) {
var test = (parameter as PivotItemEventArgs);
}

问题如下:我收到错误: type or namespace name 'PivotItemEventArgs' could not be found (are you missing a using directive or an assembly reference?) .

但是当我运行该项目时,一切正常。深入挖掘后,PivotItemEventArgs 确实位于 Windows.UI.Xaml.Controls 中,但不会在 Shared 项目中找到。

我猜这是因为枢轴项不是 Windows 8 控件。

现在我只想要 SelectedItem被传递,而不是 EventArgs。我改变了我的 CommandParameter到以下:
<Core:InvokeCommandAction Command="{Binding LoadAdditionalData}"
CommandParameter="{Binding ElementName=pvtMain, Path=SelectedItem}" />

尽管如此,该值仍然是 PivotItemEventArgs。我错过了什么吗?

最佳答案

因此,经过一番挣扎,我偶然发现了“解决方案”。

我将命令绑定(bind)在 PivotItemLoading 事件上。不知何故,在第一次加载事件触发时,参数始终是 PivotItemEventArgs 类型。 .

然而,在第二次加载之后,正确的对象(SelectedItem)正在被传递!

我不知道确切的原因,但很高兴知道这是有效的。

关于c# - CommandParameter 始终通过 ElementName 绑定(bind)传递 EventArgs,没有实际绑定(bind)值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29995263/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com