2

ばかげた質問かもしれませんが、ユーザーが画像を追加してキャンバスにあるものを保存するか、プロジェクトの要素などをサーバーとDBに保存して後で戻ってくることができる画像エディターを開発する仕事を継承しました。イメージの幅や高さなどの属性が送信され、ロード時にコールバックされるため、イメージはキャンバス上の元の場所にロードされます。

機能の一部は、画像のサイズを変更することです。画像の幅にバインドされたスライダーでこれを行っています。スライダーを使用すると画像が比例して小さくなりますが、画像の高さの値も画像の実際の高さも変化せず、データベースに保存されている高さが正しくないため、プロジェクトが再度読み込まれたときに問題が発生します。

スライダー領域の XAML:

<TextBlock Grid.Column="0" Grid.Row="0" Text="Width:" VerticalAlignment="Center" FontWeight="Bold" Margin="3" HorizontalAlignment="Left" />
                                    <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Path=Width, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="24" Margin="3" />
                                    <TextBlock Grid.Column="2" Grid.Row="0" Text="px" VerticalAlignment="Bottom" Margin="3,0,0,0" />

                                    <TextBlock Grid.Column="0" Grid.Row="1" Text="Height:" VerticalAlignment="Center" FontWeight="Bold" Margin="3" HorizontalAlignment="Left" />
                                    <TextBox x:Name="txtImageHeight" Grid.Column="1" Grid.Row="1" Text="{Binding Path=Height, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="24" Margin="3" />
                                    <TextBlock Grid.Column="2" Grid.Row="1" Text="px" VerticalAlignment="Bottom" Margin="3,0,0,0" />

                                    <TextBlock Grid.Column="0" Grid.Row="2" Text="Size:" FontWeight="Bold" Margin="3" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                    <Slider Grid.Column="1" Grid.Row="2" Minimum="0" SmallChange=".01" LargeChange=".10" Maximum="{Binding Path=MaxWidth}"
                                        Value="{Binding Path=Width, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="3" Grid.ColumnSpan="2" ValueChanged="Slider_ValueChanged" />                                     

Height テキスト ボックスの値も、明らかに変更されません。

そしてコード:

private void AddImageElement(object param)
    {
        bool? gotImage;
        string fileName;
        BitmapImage imageSource = GetImageFromLocalMachine(out gotImage, out fileName);

        if (gotImage == true)
        {
            Image image = new Image();
            image.Name = fileName;
            image.Source = imageSource;
            image.Height = imageSource.PixelHeight;
            image.Width = imageSource.PixelWidth;
            image.MaxHeight = imageSource.PixelHeight;
            image.MaxWidth = imageSource.PixelWidth;
            image.Cursor = Cursors.Hand;
            image.Tag = null;

            AddDraggingBehavior(image);
            image.MouseLeftButtonUp += element_MouseLeftButtonUp;

            this.Elements.Add(image);
            numberOfElements++;

            this.SelectedElement = image;
            this.SelectedImageElement = image;
        }
    }

画像がレンダリングされる高さを反映する高さの値を取得するにはどうすればよいですか?

私は Silverlight と .NET にまったく慣れていないので、明らかな何かが欠けている可能性があります

4

1 に答える 1

1

はい、バインディングのサイズ変更に関しては、Silverlight には既知の不十分な点がいくつかあります。少し前に、スライダーにバインドしたいスケーリング機能を備えたビューアーを作成しましたが、いくつかの小さなヘルパー ツールが必要であることがわかりました。私はLayoutTransformerSilverlight Toolkitの とAnimationMediator、Toolkit 開発者の 1 人のを使用しています。

を使用するLayoutTransformerと、そのコンテンツを画像だけでなく任意のものに設定し、それに任意の変換を適用できます。通常の とは対照的に、RenderTransformレイアウトと実際のサイズに影響します。私の要素はまだありCanvasませんので、シナリオでどのように動作するか、また使用できるかどうかはわかりませんが、このサンプルはまだ役立つ可能性があります.

<Grid>
    <fs:AnimationMediator x:Name="ScaleXMediator" LayoutTransformer="{Binding ElementName=LayoutTransformer}" AnimationValue="{Binding ScaleX, ElementName=ScaleTransform, Mode=TwoWay}" />
    <fs:AnimationMediator x:Name="ScaleYMediator" LayoutTransformer="{Binding ElementName=LayoutTransformer}" AnimationValue="{Binding ScaleY, ElementName=ScaleTransform, Mode=TwoWay}" />

    <tkt:LayoutTransformer x:Name="LayoutTransformer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <tkt:LayoutTransformer.LayoutTransform>
            <ScaleTransform x:Name="ScaleTransform" />
        </tkt:LayoutTransformer.LayoutTransform>

        <Image x:Name="MyImage" Source="mysource.png" Width="600" Height="800" />
    </tkt:LayoutTransformer>
</Grid>

ここでは MultiBinding には触れないので、さらにSliderの値変更イベントを手動で処理し、 と を適切に設定する必要AnimationValueScaleXMediatorありScaleYMediatorます。

それが役に立てば幸い!

于 2012-07-13T16:52:09.183 に答える