MVVM, связывающий с InkCanvas

Это невозможно с Тихо. Поэтому я использовал командную строку:

SET ECLIPSE_HOME=S:/Development/Eclipse 2018-12
SET EQUINOX_VERSION=1.5.200.v20180922-1751
SET CURRENT_PATH=%~dp0
SET SOURCE_REPOSITORY=%CURRENT_PATH%\dropin
SET TARGET_REPOSITORY=%CURRENT_PATH%\


java -jar "%ECLIPSE_HOME%/plugins/org.eclipse.equinox.launcher_%EQUINOX_VERSION%.jar" 
    -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher 
    -metadataRepository "file:/%TARGET_REPOSITORY%" -artifactRepository "file:/%TARGET_REPOSITORY%" 
    -source "%SOURCE_REPOSITORY%" -publishArtifacts -append 

Однако я не смог создать категории, поэтому хранилище по умолчанию выглядит пустым.

5
задан cjibo 7 April 2009 в 23:38
поделиться

1 ответ

The problem with your approach is that you assume the InkCanvas creates the StrokeCollection. It does not - it merely adds and removes items from it. And if the collection isn't available (ie. is null), the binding will fail and the InkCanvas won't do anything with it. So:

  1. You need to create a single StrokeCollection
  2. You need to assume the contents of the collection will change, not the collection itself

Example code:

public class ViewModel : INotifyPropertyChanged
{
    private readonly StrokeCollection _strokes;

    public ViewModel()
    {
        _strokes = new StrokeCollection();
        (_strokes as INotifyCollectionChanged).CollectionChanged += delegate
        {
            //the strokes have changed
        };
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public StrokeCollection Signature
    {
        get
        {
            return _strokes;
        }
    }

    private void OnPropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;

        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

And XAML:

<InkCanvas Strokes="{Binding Signature}"/>
11
ответ дан 18 December 2019 в 13:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: