我有一个名为 DataModel
的类,我在其中存储有关应用程序状态的所有信息。在那里我有一个名为 DeviceInput
的属性,类型为 CoreInputDeviceTypes
。这就是我保存是否为我的 InkCanvas
启用触摸的值。我想将我的 InkCanvas.InkPresenter.InputDeviceTypes
属性绑定(bind)到 DeviceInput
属性。我创建了一个 Binding
:
Binding inputBinding = new Binding();
inputBinding.Source = DataModel.DeviceInput;
inputBinding.Mode = BindingMode.OneWay;
问题是我找不到任何方法来设置 InkCanvas.InkPresenter.InputDeviceTypes
属性的绑定(bind)。如果我尝试这样做:
MyInkCanvas.SetBinding(InkCanvas.InkPresenter...)
InkPresenter
不可用。这是有道理的,因为 InkPresenter
是一个子项,而不是一个依赖属性。但我也做不到
MyInkCanvas.InkPresenter.SetBinding(...)
我猜这是因为 InkPresenter
来自 Windows.UI.Inking
而不是 Windows.UI.Xaml
。但是有什么方法可以对此属性设置绑定(bind)吗?
最佳答案
我认为您可以使用自定义依赖属性解决此问题。类似于以下内容:
public static readonly DependencyProperty InputDTsProperty =
DependencyProperty.Register("InputDTs", typeof(Windows.UI.Core.CoreInputDeviceTypes), typeof(MainPage), new PropertyMetadata(null, new PropertyChangedCallback(InputDTsPropertyChanged)));
public Windows.UI.Core.CoreInputDeviceTypes InputDTs
{
//get;
//set;
}
private static void InputDTsPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
//set MyInkCanvas.InkPresenter.InputDeviceTypes here
}
public MainPage()
{
this.InitializeComponent();
Binding inputBinding = new Binding();
inputBinding.Source = DataModel.DeviceInput;
inputBinding.Mode = BindingMode.OneWay;
this.SetBinding(InputDTsProperty, inputBinding);
}
关于c# - 设置 InkCanvas.InkPresenter 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32890220/