【发布时间】:2018-10-24 16:10:37
【问题描述】:
我目前正在处理一个 UWP 项目,我正在尝试将当前页面中的一些命令绑定到用户控件。
虽然其他所有属性似乎都已正确绑定,但该命令未正确绑定,因此无法正常工作。
你知道它可能来自哪里吗?
这是我的代码(主页):
<Grid Visibility="{Binding LoginStep, Converter={StaticResource LogConverter}, ConverterParameter='InputPin'}"
Height="450px" Width="280px">
<PIN:PinInput Pin="{Binding CurrentUser.Pin, Mode=TwoWay}" x:Uid="btnPin" SubmitCommand="{Binding AddPinCommand, Mode=TwoWay}"></PIN:PinInput>
</Grid>
查看模型:
private ICommand _addPinCommand;
public ICommand AddPinCommand
{
get
{
return _addPinCommand ?? (_addPinCommand = new CommandBase((o) =>
{
this.LoginStep = LoginStep.ChoseCompany;
}));
}
}
用户控制:
DataContext="{Binding RelativeSource={RelativeSource Self}}"
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Style="{StaticResource btnStyle}" Command="{Binding SubmitCommand, Mode=TwoWay}">
<StackPanel>
<Border Style="{StaticResource btnInnerStyle}" Width="100px" CornerRadius="10">
<TextBlock Text="{Binding SubmitButtonText}" Style="{StaticResource btnText}"></TextBlock>
</Border>
</StackPanel>
</Button>
</Grid>
public static readonly DependencyProperty submitCommandProperty = DependencyProperty.Register("SubmitCommand", typeof(ICommand), typeof(PinInput), null);
public ICommand SubmitCommand
{
get
{
return (ICommand)GetValue(submitCommandProperty);
}
set
{
SetValue(submitCommandProperty, value);
}
}
注意:
在错误日志中我有: 错误:BindingExpression 路径错误:在“PAT.Mobile.UTrakk.UWP.Views.Components.PinInput”上找不到“AddPinCommand”属性。 BindingExpression:路径='AddPinCommand' DataItem='PAT.Mobile.UTrakk.UWP.Views.Components.PinInput';目标元素是'PAT.Mobile.UTrakk.UWP.Views.Components.PinInput'(名称='null');目标属性是“SubmitCommand”(输入“ICommand”)
提前致谢,
托马斯 K.T.
【问题讨论】:
标签: data-binding uwp icommand