2012-02-20 98 views
1

按鈕的命令是ExcelExportCommand其CommandParameter是這樣的:WPF的SelectedIndex CommandParameter

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

我怎樣才能通過視圖模型編程方式獲得的SelectedIndex?我是新來的MVVM模式,我想驗證我採取了正確的方法。你能幫我嗎?

在此先感謝

回答

0

您可以ListTabControl的SelectedIndex屬性綁定到您的視圖模型的整數屬性:

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

private int _ListSelectedIndex; 
public int ListSelectedIndex { 
    get { return _ListSelectedIndex;} 
    set 
    { 
     _ListSelectedIndex = value; 
     OnPropertyChanged("ListSelectedIndex"); // if INotifyPropertyChanged implemented 
    } 
} 
+0

感謝隊友確實 – bilgestackoverflow

+0

@bilgestackoverflow如果這是正確的回答你,所以請標記它。 –

相關問題