사용자가 TextBox에 내용을 입력하고 Enter 단추를 누르십시오. Enter-button을 누르면 AddFieldCommand
이 호출됩니다. XAML에서 어떻게 할 수 있습니까?사용 방법 EventToCommand - XAML 오류
내 코드에서 "속성 '텍스트'가 두 번 이상 설정되었습니다."라는 경고 메시지가 나타납니다.
캔버스의 어떤 개체가 업데이트되고 있는지 알 필요가 있으므로 TextBox의 콘텐츠를 내 모델에 추가 할 수 있습니다. 이것이 내가 EventToCommand
을 사용하는 이유입니다.
<TextBox x:Name="txtFields" Text="{Binding FieldsTextProperty, UpdateSourceTrigger=PropertyChanged}" Height="23" TextWrapping="NoWrap" Background="#FFCBEECD" AcceptsReturn="False" >
<TextBox.InputBindings>
<KeyBinding Key="Enter" >
</KeyBinding>
</TextBox.InputBindings>
<i:EventTrigger EventName="AddField">
<cmd:EventToCommand Command="{Binding DataContext.AddFieldCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</TextBox>
아무도 도와 줄 수 있습니까? 당신은 당신이 버튼을 바인더 제본 명령을 실행할 입력을 클릭하면
그러나 사용자가 Enter-button을 눌렀을 때 어떻게'EventToCommand'를 트리거 할 수 있습니까? 그리고 귀하의 연습에 대해 많은 감사드립니다! – MikaelKP
설정에 따라,'AddField' 이벤트가 발생할 때 명령이 실행됩니다. ['KeyPress'] (http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx) 이벤트를 듣고 (그리고 키를 눌렀는지 확인하십시오. Enter 키). 'TextBox'를 서브 타입 화하고 EventTrigger를 사용할 수있는'EnterKeyPressed' 이벤트를 추가 할 수 있습니다. – poke