我在XAML中定義的列表視圖,請參見下面的片段:編譯錯誤列表視圖XAML代碼與結合
<Grid>
<Button Content="_Generate List ..." Height="23" HorizontalAlignment="Right" Margin="0,0,12,12" Name="buttonGenerateLists"
VerticalAlignment="Bottom" Click="ButtonGenerateListsClick" Width="108" Grid.Column="1" />
<ListView HorizontalAlignment="Stretch" Margin="275,34,13,96" Name="listViewPatches" VerticalAlignment="Stretch" SelectionMode="Extended"
VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" AlternationCount="1" GotFocus="ListViewPatchGotFocus"
MouseDoubleClick="{Binding Path=EditSelectedItemCommand}" SelectedItem="{Binding IsSelected}">
我也得到了以下編譯錯誤:
Error 1 MouseDoubleClick="{Binding Path=EditSelectedItemCommand}" is not valid. '{Binding Path=EditSelectedItemCommand}' is not a valid event handler method name. Only instance methods on the generated or code-behind class are valid. Line 12 Position 19. G:\Data\Eigen\Informatica\KorgKronosTools\KorgKronosTools\PcgWindow.xaml 12 19 PcgTools
(注:第12行是上面片段中的最後一行)。
我想我沒在下面的片段背後我的代碼設置數據上下文正確的,但是編碼:
public PcgWindow(MainWindow mainWindow, string pcgFileName, PcgMemory pcgMemory)
{
InitializeComponent();
_mainWindow = mainWindow;
_viewModel = new PcgViewModel(mainWindow.ViewModel);
...
DataContext = _viewModel;
我定義的視圖模型綁定本身:
ICommand _editSelectedItemCommand;
public ICommand EditSelectedItemCommand
{
get
{
return _editSelectedItemCommand ?? (_editSelectedItemCommand = new RelayCommand(param => EditSelectedItem(),
param => CanExecuteEditSelectedItem()));
}
}
有人可以幫我解決編譯錯誤嗎?
在此先感謝。
謝謝你,它的工作...我用的按鈕,工具欄等的命令,但這並不在列表視圖中,雙擊運行。 – 2012-02-12 14:26:49
感謝您的澄清......我可能會使用該方法來清理代碼背後的代碼(並且我已經實現了該命令本身)。 – 2012-02-12 14:32:56