110,538
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:WpfApplic"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<local:PositionConverter x:Key="conver"></local:PositionConverter>
</Window.Resources>
<Grid>
<Slider Height="21" Margin="33,0,20,11" Name="slider1" VerticalAlignment="Bottom" Value="5" />
<ScrollViewer Margin="0,0,0,50" Name="scrollViewer1" VerticalAlignment="Top" >
<Image Margin="10,10,10,88" Name="image1" Source="C:\Documents and Settings\ch\桌面\100_3118副本2.jpg" Stretch="Fill" >
<Image.Width>
<Binding Path="Value" ElementName="slider1" Converter="{StaticResource conver}" ></Binding>
</Image.Width>
<Image.Height>
<Binding Path="Value" ElementName="slider1" Converter="{StaticResource conver}"></Binding>
</Image.Height>
</Image>
</ScrollViewer>
</Grid>
</Window>
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;
namespace WpfApplic
{
/// <summary>
/// 宽度值与slider的value的转换
/// </summary>
public class WidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
float va = float.Parse(value.ToString()) * 50; //宽度缩放50倍
return (va);
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
float va = float.Parse(value.ToString()) / 50;
return (va);
}
return string.Empty;
}
}
/// <summary>
/// 高度值与slider的value的转换
/// </summary>
public class HeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
float va = float.Parse(value.ToString()) * 60;//高度缩放60倍
return (va);
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
float va = float.Parse(value.ToString()) / 60;
return (va);
}
return string.Empty;
}
}
}