Skip to content

ReorderListBox doesn't support hybrid Winform applications #30

@jonashogstrom

Description

@jonashogstrom

If a ReorderListBox will throw a NullReferenceException when used in a winform hybrid application. the reason is that the DragPreviewAdorner uses Application.Current, but this static property is not assigned when running in a winform application. A solution is to change the following method:

    private static void GetCurrentDPI(out double x, out double y)
    {
        Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;
        x = 96 / m.M11;
        y = 96 / m.M22;
    }

to

    private static void GetCurrentDPI(out double x, out double y, FrameworkElement element)
    {
        Matrix m = PresentationSource.FromVisual(element).CompositionTarget.TransformToDevice;
        x = 96 / m.M11;
        y = 96 / m.M22;
    }

and pass the current element in SetPreviewElement:

    public void SetPreviewElement(FrameworkElement element)
    {
        //...
        GetCurrentDPI(out x, out y, element);

Side note: the class NotifyWorker seems to have the same issue in the OnClientException method... haven't looked at how that could be handled. We aren't using that class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions