나는 다음과 같은 XAML 코드가 :WPF에서 명령 바인딩의 기본 매개 변수는 무엇입니까?
<Window x:Class="MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MVVM"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="abc" Command="{Binding Path=MyCommand}" Grid.Row="1" />
</Grid>
</Window>
가 MyCommand
동안 ICommand의 속성입니다. 명령은 문제없이 호출되지만 매개 변수는 항상 null
입니다.
기본값으로 사용하거나 DataContext
설정에 문제가 있습니까?
내가 잘못했으면 무엇을해야합니까?
- 나는 매개 변수는 디버거에서 널 알고, 내 명령 코드가 항상 함께 메시지 박스를 보여줍니다
(p) => { System.Windows.MessageBox.Show(p?.ToString() ?? "p is null"); }
을, 때문에 "P는 null입니다."
다른 모든 것들이'string test = "example text";'와 같은 안정적인 문자열을 시도하기 전에 테스트를 위해 나타나면 바인딩에 사용하십시오. 그러면 문제가 'p' 문자열 변수에 있습니다. –