设置InkCanvas.InkPresenter绑定

时间:2015-10-01 14:33:04

标签: c# data-binding windows-10 uwp

我有一个名为DataModel的班级,我在那里存储有关我的应用状态的所有信息。在那里,我有一个名为DeviceInput的属性,输入为CoreInputDeviceTypes。这就是我保持是否为我的InkCanvas启用触摸的值。我想将InkCanvas.InkPresenter.InputDeviceTypes属性绑定到DeviceInput属性。我创建了一个Binding

Binding inputBinding = new Binding();
inputBinding.Source = DataModel.DeviceInput;
inputBinding.Mode = BindingMode.OneWay;

问题是我找不到任何方法来设置绑定到InkCanvas.InkPresenter.InputDeviceTypes属性。如果我试着这样做:

MyInkCanvas.SetBinding(InkCanvas.InkPresenter...)

InkPresenter不可用。这是有道理的,因为InkPresenter是子项,而不是依赖项属性。但我也不能这样做

MyInkCanvas.InkPresenter.SetBinding(...)

我猜这是因为InkPresenter来自Windows.UI.Inking而不是Windows.UI.Xaml。但有没有办法在这个属性上设置绑定?

1 个答案:

答案 0 :(得分:0)

我认为您可以使用自定义依赖项属性解决此问题。如下所示:

    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);
    }