WPF의 명령을 컨트롤의 더블 클릭 이벤트 핸들러에 바인딩하는 방법은 무엇입니까?
텍스트 블록(또는 잠재적으로 이미지)의 더블 클릭 이벤트를 View Model의 명령에 바인딩해야 합니다.
텍스트 차단.InputBindings가 내 명령에 올바르게 바인딩되지 않는 것 같습니다. 도움이 필요합니까?
<Button>
<Button.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="YourCommand" />
</Button.InputBindings>
</Button>
http://thejoyofcode.com/Invoking_a_Command_on_a_Double_Click_or_other_Mouse_Gesture.aspx
MVVM 방식을 사용하는 것은 간단합니다. 저는 여기서 배우기 쉽고 강한 MVVM Light를 사용합니다.
1.xmlns 선언에 다음 행을 입력합니다.
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;
assembly=GalaSoft.MvvmLight.Extras.WPF4"
2. 텍스트 블록을 다음과 같이 수정합니다.
<textBlock text="Text with event">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<GalaSoft_MvvmLight_Command:EventToCommand
Command="{Binding Edit_Command}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</textBlock>
3.그런 다음 뷰 모델에 명령 코드를 작성합니다!!!
ViewModel1.cs
Public RelayCommand Edit_Command
{
get;
private set;
}
Public ViewModel1()
{
Edit_Command=new RelayCommand(()=>execute_me());
}
public void execute_me()
{
//write your code here
}
Real ERP 애플리케이션에서 사용한 적이 있기 때문에 당신에게 도움이 되길 바랍니다.
말론 그레치의 첨부된 명령 동작을 시도해 보십시오.
목록 보기의 MouseDoubleClick 이벤트를 ViewModel의 명령에 바인딩해야 하는 비슷한 문제도 있었습니다.
제가 생각해낸 가장 간단한 해결책은 원하는 명령 바인딩이 있는 더미 버튼을 넣고 마우스 더블클릭 이벤트의 이벤트 핸들러에서 버튼 명령의 실행 메서드를 호출하는 것입니다.
.xaml
<Button Visibility="Collapsed" Name="doubleClickButton" Command="{Binding Path=CommandShowCompanyCards}"></Button>
<ListView MouseDoubleClick="ListView_MouseDoubleClick" SelectedItem="{Binding Path=SelectedCompany, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" Margin="0,10,0,0" ItemsSource="{Binding Path=CompanyList, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" HorizontalContentAlignment="Stretch" >
비밀번호.
private void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
doubleClickButton.Command.Execute(null);
}
그것은 간단하지 않지만 정말 간단하고 효과가 있습니다.
언급URL : https://stackoverflow.com/questions/1293530/how-to-bind-a-command-in-wpf-to-a-double-click-event-handler-of-a-control
'codememo' 카테고리의 다른 글
| 다양한 어레이 요소를 새 어레이로 복제하려면 어떻게 해야 합니까? (0) | 2023.05.13 |
|---|---|
| Git에서 파일 이름의 대문자화를 어떻게 변경합니까? (0) | 2023.05.13 |
| SQL Server에서 제약 조건의 이름을 바꾸시겠습니까? (0) | 2023.05.13 |
| 현재 및 미래의 모든 리포지토리에 Git 사후 커밋 후크 적용 (0) | 2023.05.13 |
| 빈 값 또는 null 값을 확인하는 가장 좋은 방법 (0) | 2023.05.13 |