UserControl Рисование Silverlight 4 - PullRequest
0 голосов
/ 21 апреля 2011

Я создал usercontrol просто для того, чтобы содержать Image, потому что я должен использовать методы Measureoverride иrangeoverride, и я не могу создать подкласс (Image is seled) ... в любом случае, дело в том, что когда я вызываю this.Image.Measure (SizeIwantto to the image) поле требуемого размера изображения не установлено ... кто-нибудь знает почему?Я управлял методами Layouting раньше, и это сработало ... Вот код (я уже проверил все другие размеры, и ни один из них не равен 0 или NaN)

    protected override Size MeasureOverride(Size availableSize)
    {


        //the size that the element wants to have
        Size imageDesiredSize = new Size();

        imageDesiredSize = availableSize;
        //if the current element's size is a pertentage
        if ((futureHeight != 0))
        {
            imageDesiredSize.Height = availableSize.Height * futureHeight / 100;
        }
        if ((futureWidth != 0))
        {
            imageDesiredSize.Width = availableSize.Width * futureWidth / 100;
        }

        if (widthWrap)
        {
            imageDesiredSize.Width = ((BitmapImage)this.Source).PixelWidth;
        }
        if (heightWrap)
        {
            imageDesiredSize.Height = ((BitmapImage)this.Source).PixelHeight;
        }
        System.Diagnostics.Debug.WriteLine("imagedesired" + imageDesiredSize);
        this.image.Measure(imageDesiredSize);
        System.Diagnostics.Debug.WriteLine("desiredsize" + this.image.DesiredSize);

        return imageDesiredSize;
    }

1 Ответ

0 голосов
/ 26 апреля 2011

В конце концов это было действительно простое решение ... В конструкторе UserControl я добавил эту строку: this.Content = image;И теперь содержимое Usercontrol рисуется на экране: -)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...