也许一个愚蠢的问题,但我继承开发的图像编辑器,允许用户添加图像,然后要么保存的是在画布上,或项目的内容等保存到服务器的工作和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