使用在类的属性中获取/设置的新方法,如:
public string FirstName {
get; set;
}
Run Code Online (Sandbox Code Playgroud)
为什么不简单地将属性FirstName公开而没有访问者?
我将我的xaml中两个超链接的command属性绑定到视图中的命令(这是datacontext):
<TextBlock>
<Hyperlink x:Name="linkCheckAll" Command="{Binding CheckAllZonesCommand}" CommandParameter="{Binding}">Check All</Hyperlink>
<TextBlock Margin="0,0,20,0"/>
<Hyperlink x:Name="linkUncheckAll" Command="{Binding UncheckAllZonesCommand}" CommandParameter="{Binding}">Uncheck All</Hyperlink>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
绑定命令时出现以下错误:
System.Windows.Data Error: 40 : BindingExpression path error: 'CheckAllZonesCommand' property not found on 'object' ''ZonesView' (HashCode=56756307)'. BindingExpression:Path=CheckAllZonesCommand; DataItem='ZonesView' (HashCode=56756307); target element is 'Hyperlink' (HashCode=50738642); target property is 'Command' (type 'ICommand')
System.Windows.Data Error: 40 : BindingExpression path error: 'UncheckAllZonesCommand' property not found on 'object' ''ZonesView' (HashCode=56756307)'. BindingExpression:Path=UncheckAllZonesCommand; DataItem='ZonesView' (HashCode=56756307); target element is 'Hyperlink' (HashCode=53994596); target property is 'Command' (type 'ICommand')
Run Code Online (Sandbox Code Playgroud)
"ZonesView"是我的dataContext,我很肯定它包含有问题的命令:
public class …
Run Code Online (Sandbox Code Playgroud)