2016-06-27 9 views
0

나는 비슷한 질문을 몇 번 보았으므로 신속하게 기각하지 마십시오. 시나리오가 여기에서 다르게 보입니다. 왜 잘못 될지 알 수 없습니다. 내 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> 

는 I에 유래 및 기존 사용자 기여에 대한 방법론 감사를 발견했다. 매우 감사.

이 문제는 MouseBinding CommandParameter과 관련이 있습니다. 프로그램은 경고없이 잘 실행됩니다. DataGrid에있는 행을 두 번 클릭하면 설계된대로 동작합니다.

하지만 비주얼 스튜디오 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')

가 왜 이런 말된다? ItemSourceCollectionViewSource 개체이기 때문에 /을 사용했으며 현재 선택한 항목을 호출하는 것으로 알고 있습니다. 하지만 실제로이 행을 두 번 클릭하기 전까지는이 명령이 실행되지 않습니다.

내 출력 창에 어떻게 나타나는지 궁금합니다.

나는 대답 당 나는이 예외가로 바인딩을 변경하려고하는 경우 :

Exception error

업데이트 : 지금

<MouseBinding 
    MouseAction="LeftDoubleClick" 
    Command="{Binding EditStudentButtonClickCommand}" 
    CommandParameter="{Binding /, Source={RelativeSource Self}}" /> 

그러나 다음은

현재 XAML입니다 출력 창에 다음과 같이 표시됩니다.

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입니다 :

내가 할 tryign 나는 무엇
<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> 

가 변경되지 않은이 - 사용자의 (a CVS에 boudn되는) 데이터 그리드 행을 두 번 클릭 할 때 해당 행을 기반으로 명령을 호출합니다. 입력의 맥락에서

+0

'(T) 매개 변수'만 쓰면 'Convert.ChangeType'을 사용하지 마십시오. –

+0

'RelativeSource' * 확장자 *는'RelativeSource' * 속성에만 유효합니다,'Source'가 아닙니다. 또한'RelativeSource Self'는 반드시 여러분의 컬렉션이 아닌'MouseBinding'을 참조 할 것입니다. –

+0

@ H.B. 업데이트 된 질문 (아래). –

답변

2

DataContext 변경하지 말았어야 바인딩 그래서 내가 올바른 바인딩 것으로 기대 :

보다
CommandParameter="{Binding Path=/, Source={StaticResource cvsStudentList}}" 

기타 당신은 또한 어떤 경우, RelativeSource를 통해 SelectedItem에 바인딩 할 수 있습니다 동등한 것.

CommandParameter="{Binding Path=SelectedItem, 
          RelativeSource={RelativeSource AncestorType=DataGrid}}" 
+0

감사합니다. 정적 리소스로이 첫 번째 접근 방식을 시도하면 두 번 클릭 할 때 예외가 발생합니다. –

+0

"예외"는별로 도움이되지 않습니다. 문제는 바인딩 자체가 작동하는지 여부와 명령 구현이 매개 변수로 전달 될 것으로 기대되는 것입니다. –

+0

나는 이것을 할 수 없다. 이 매개 변수는 cvs 소스의 ** 항목 **입니다. 내 질문에 예외가 추가됩니다. 내가 아는 전부는 내가 혼자서 사용해야 만한다는 것입니다. 그러나 나는 그 침묵의 예외를 얻는다. 설명대로 바인딩을 사용하면 예외가 발생합니다. 당신이 언급 한 SelectedItem 아이디어에 대한 답변을 보여 주시겠습니까? 감사. –