我有這樣的風格:需要協助解決一個問題BindingExpression
<DataTemplate>
<Button
Width="44"
Height="24"
VerticalAlignment="Top"
VerticalContentAlignment="Center"
HorizontalAlignment="Left"
HorizontalContentAlignment="Center"
Command="{Binding UninspectedPrintSelectedCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Content}">
但命令無法正常工作。縱觀輸出窗口產生此問題:
System.Windows.Data Error: 40 : BindingExpression path error: 'UninspectedPrintSelectedCommand' property not found on 'object' ''String' (HashCode=701007577)'. BindingExpression:Path=UninspectedPrintSelectedCommand; DataItem='String' (HashCode=701007577); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')
視圖模型的ICommand屬性:
public ICommand UninspectedPrintSelectedCommand
{
get
{
return new DelegateCommand<object>((print) =>
{
string printName = print.ToString();
int indexOfX = printName.IndexOf('x');
Row = DiePrint.GetRow(printName);
Col = DiePrint.GetCol(printName);
if (diePrint == null) { diePrint = new DiePrint(Row + "x" + Col); }
else
{
diePrint.Row = Convert.ToInt32(row);
diePrint.Col = Convert.ToInt32(col);
}
LoadMap();
});
}
}
我不知道如何解決這個問題。 Button的Command屬性如何被解釋爲一個字符串?
如果這意味着什麼,這是我的App.xaml文件,而不是主窗口。
代碼的財產? –
要綁定到'Button'的'DataContext',這將要被設置爲用於實例化使用'DataTemplate'相關聯的視圖的對象。基於輸出,DataTemplate必須用於字符串。 – Xavier
@MatthewFrontino我還說,我試圖綁定到這個問題 – kformeck