我有一个自定义 TextBox,它执行一些奇特的输入处理以确保只输入数值:
public class NumericTextBox : TextBox
{
// Some fancy input-handling here
}
我还有一个 ViewModel,它有一个公共(public)属性来存储计数:
public class TheViewModel : ReactiveObject
{
public int Count { get; set; }
}
我有一个包含名为 Count 的 NumericTextBox 的 View :
<Window x:Class="MyProject.TheView"
xmlns:controls="clr-namespace:MyProject.Controls">
<controls:NumericTextBox
Name="Count">
</Window>
将它绑定(bind)到 ViewModel:
public partial class TheView: Window, IViewFor<TheViewModel>
{
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register("ViewModel",
typeof(TheViewModel),
typeof(TheView));
public TheView()
{
InitializeComponent();
}
/// <summary/>
object IViewFor.ViewModel
{
get { return ViewModel; }
set { ViewModel = (TheViewModel)value; }
}
/// <summary>
/// The ViewModel corresponding to this specific View. This should be
/// a DependencyProperty if you're using XAML.
/// </summary>
public TheViewModel ViewModel
{
get
{
return (TheViewModel) GetValue(ViewModelProperty);
}
set
{
SetValue(ViewModelProperty, value);
BindToViewModel();
}
}
private void BindToViewModel()
{
this.Bind(ViewModel, vm => vm.Count, v => v.Count.Text);
}
}
当我尝试编译时,VS 提示绑定(bind)到 TheView 中的计数:
Cannot convert lambda expression to type 'object' because it is not a delegate type
如果我将 NumericTextBox 换成普通的 TextBox,它工作正常。有什么我想念的吗?
最佳答案
关于c# - 无法绑定(bind)到 ReactiveUI 中覆盖的 WPF TextBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33793271/