也許一個愚蠢的問題,但我繼承開發的圖像編輯器,允許用戶添加圖像,然後要麼保存的是在畫布上,或項目的內容等保存到服務器的工作和DB稍後再回來。圖像寬度和高度等屬性會在加載時發送並回調,以便將圖像加載回畫布上的位置。調整大小使用滑塊圖像在Silverlight
部分功能是重新調整圖像大小。我正在用一個綁定到圖像寬度的滑塊來做這件事。當我使用滑塊時,圖像比例變小,但圖像高度的值和圖像實際高度不會改變,這會在存儲在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" />
在高度文本框中的值顯然不會改變,因爲我想無論是。
,代碼:
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所以也許我失去了一些東西明顯
因爲我需要我的形象無論如何約束比例,我結束了剛剛起步的圖像的高度和寬度之間的初始比率和我有當寬度與改變,改變高度值寬度的文本改變事件處理程序滑塊基於保持相同的比例。一種屠殺的嘗試,但它似乎工作正常。任何人看到我做到這一點的任何大問題? – Steve 2012-07-16 11:25:31