gpt4 book ai didi

c# - 如何使用 Caliburn 将 Pivot 集中在 ViewModel 中的特定 PivotItem 上

转载 作者:行者123 更新时间:2023-12-03 10:36:16 25 4
gpt4 key购买 nike

使用通用应用程序(WP8.1 项目)的 Caliburn MVVM 模式,我希望从代码中将 PivotPage 集中在该页面的 Caliburn ModelView 中的特定 PivotItem 上。请注意,有时我对使用 Conductor 类不感兴趣,因为 MyPivot 页面的所有 PivotItems 都有一个公共(public) DataSource,所以我认为在这种情况下,为每个 PivotItem 拥有多个 ViewModel 是没有用的。

我想在 MyPivotViewModel 中做的是应该以这种方式在代码隐藏中做的事情:

        pvMyPivot.SelectedIndex = 2;

或者
        pvMyPivot.SelectedItem = Pivot2Name;

任何建议和示例代码表示赞赏;-)

最佳答案

如果需要从 View 模型中绑定(bind),您可以绑定(bind)到 SelectedIndex 或 SelectionChanged 事件或两者……只需复制事件签名,因为 SelectedIndex 将是一个整数属性。

private int _pivotindex;
public int PivotIndex{
get{ return _pivotindex;}
set{
_pivotindex = value;
NotifyOfPropertyChanged();
}
}

public void SelectionChanged( SelectionChangedEventArgs e){

}

然后在你的 xaml 中你会
<Pivot  SelectedIndex="{Binding PivotIndex, Mode=TwoWay}"
cm:Message.Attach="[Event SelectionChanged] = [Action SelectionChanged($eventArgs)]" />

例如...

另一个答案可能会将通用类型换成 Pivot,但可能必须从那里进行修改以合并更改以适应 WinRT,而不是 Panorama 中的 Silverlight ......

关于c# - 如何使用 Caliburn 将 Pivot 集中在 ViewModel 中的特定 PivotItem 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26815169/

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