首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wpf SelectedIndex CommandParameter

wpf SelectedIndex CommandParameter
EN

Stack Overflow用户
提问于 2012-02-20 15:50:15
回答 1查看 1.1K关注 0票数 1

按钮的命令是ExcelExportCommand,它的CommandParameter类似于:

代码语言:javascript
复制
<Button x:Name="ExcelExport" Grid.Row="1" Height="25" Width="100" Command="{Binding ExcelExportCommand}" CommandParameter="{Binding ElementName=ListTabControl, Path=SelectedIndex}">Export to Excel</Button>

如何以编程方式通过ViewModel获取SelectedIndex?我是MVVM模式的新手,我想验证我是否采取了正确的方法。你能帮上忙吗?

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-20 16:45:32

您可以将ListTabControl的SelectedIndex属性绑定到视图模型中的整数属性:

<List x:Name="ListTabControl" SelectedIndex="{Binding ListSelectedIndex}" />

代码语言:javascript
复制
private int _ListSelectedIndex;
public int ListSelectedIndex {
    get { return _ListSelectedIndex;}
    set
    {
        _ListSelectedIndex = value;
        OnPropertyChanged("ListSelectedIndex"); // if INotifyPropertyChanged implemented
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9357763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档