button1.CommandParameter = new Binding() { Path = new PropertyPath("Text"), Source = textbox };
void cmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show(e.Parameter.ToString());
}
上面是我写的给CommandParameter设置Binding的代码,为什么没能达到效果?XAML中只要CommandParameter="{Binding ElementName=textbox,Path=Text}"就可以了。
------解决思路----------------------
button1.SetBinding(Button.CommandParameterProperty,
new Binding() { Source = textbox, Path = new PropertyPath("Text") });