我看過幾個類似的問題,所以請不要快速解僱它。這種情況在這裏看起來不同,我不明白爲什麼它會出錯。我DataGrid
有一些綁定按鍵和鼠標點擊:BindingExpression路徑錯誤:''在'當前集合項目'找不到''屬性... BindingExpression:Path = /;
<DataGrid x:Name="gridStudents" ItemsSource="{Binding Source={StaticResource cvsStudentList}}"
Margin="2"
Height="250"
SelectedItem="{Binding SelectedStudentItem, UpdateSourceTrigger=PropertyChanged}"
AutoGenerateColumns="False" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" SelectionChanged="gridStudents_SelectionChanged">
<DataGrid.InputBindings>
<MouseBinding
MouseAction="LeftDoubleClick"
Command="{Binding EditStudentButtonClickCommand}"
CommandParameter="{Binding /}" />
<KeyBinding Key="Delete" Command="{Binding DeleteStudentButtonClickCommand}" />
</DataGrid.InputBindings>
我找到了方法論感謝StackOverflow的和現有用戶的貢獻。非常感激。
此問題與MouseBinding CommandParameter
有關。程序運行正常,沒有警告。我可以雙擊DataGrid
中的任意一行,它的行爲如同設計。
但是,如果我在Visual Studio 2015年檢查輸出窗戶,我可以看到這句話:
System.Windows.Data Error: 40 : BindingExpression path error: '' property not found on 'current item of collection' ''OCLMEditorModelView' (HashCode=43686667)'. BindingExpression:Path=/; DataItem='OCLMEditorModelView' (HashCode=43686667); target element is 'MouseBinding' (HashCode=49684624); target property is 'CommandParameter' (type 'Object')
爲什麼這樣說呢?我使用/
,因爲ItemSource
是一個CollectionViewSource
對象,我明白/調用當前選擇的項目。但是,直到我實際上雙擊一行,這個命令纔會被觸發。
好奇的是我怎樣才能阻止它出現在我的輸出窗口中。
如果我嘗試更改綁定爲每答案我得到這個異常:
更新:
這是當前XAML:
<MouseBinding
MouseAction="LeftDoubleClick"
Command="{Binding EditStudentButtonClickCommand}"
CommandParameter="{Binding /, Source={RelativeSource Self}}" />
但現在我注意到這在輸出窗口中:
System.Windows.Data Error: 40 : BindingExpression path error: '' property not found on 'current item of collection' ''RelativeSource' (HashCode=472027)'. BindingExpression:Path=/; DataItem='RelativeSource' (HashCode=472027); target element is 'MouseBinding' (HashCode=36454430); target property is 'CommandParameter' (type 'Object')
它似乎工作(我可以雙擊一行,它做我想要的)。那麼我可以停止這個輸出警告嗎?
更新:
所以這是當前XAML:
<DataGrid x:Name="gridStudents" ItemsSource="{Binding StudentsView}"
Margin="2"
Height="250"
SelectedItem="{Binding SelectedStudentItem, UpdateSourceTrigger=PropertyChanged}"
AutoGenerateColumns="False" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" SelectionChanged="gridStudents_SelectionChanged">
<DataGrid.InputBindings>
<MouseBinding
MouseAction="LeftDoubleClick"
Command="{Binding EditStudentButtonClickCommand}"
CommandParameter="{Binding /, Source={RelativeSource Self}}" />
<KeyBinding Key="Delete" Command="{Binding DeleteStudentButtonClickCommand}" />
</DataGrid.InputBindings>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</DataGrid.CellStyle>
我tryign做什麼並沒有改變 - 當用戶雙擊一個DataGrid行(這是boudn到CVS)它會根據該行調用一個命令。
不要使用'Convert.ChangeType'來寫'(T)parameter'。 –
'RelativeSource' *擴展*只對'RelativeSource' *屬性*有效,而不是'Source'。另外'RelativeSource Self'會引用'MouseBinding'這肯定不是你的集合,你甚至在做什麼...... –
@ H.B。更新了問題(底部)。 –