0
我有一個項目mvvm。我通過點擊我的項目中的加載按鈕來以.jpg格式加載圖像。我想選擇這個形象的一部分,移動它,並重新它的大小,例如在我的菜單矩形工具漆通過點擊,但我不知道如何wpf mvvm ImageSelector
視圖代碼:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="240*" />
<RowDefinition Height="60*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<Image Source="{Binding MyImage.Source}" ></Image>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Button Width="70" Height="40" Command="{Binding LoadCommand}">Load Image</Button>
</StackPanel>
</Grid>
視圖模型代碼:
#region Property
private Image _MyImage;
public Image MyImage
{
get
{
return _MyImage;
}
set
{
_MyImage = value;
OnPropertyChanged("MyImage");
}
}
#endregion
#region Constructor
public ImageViewModel()
{
_MyImage = new Image();
}
#endregion
#region Commands
RelayCommand _LoadCommand;
public ICommand LoadCommand
{
get
{
if (_LoadCommand == null)
{
_LoadCommand = new RelayCommand(param => LoadCommandExecute());
}
return _LoadCommand;
}
}
#endregion
#region Methods
private void LoadCommandExecute()
{
OpenFileDialog op = new OpenFileDialog();
op.Title = "Select a picture";
op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"Portable Network Graphic (*.png)|*.png";
if (op.ShowDialog() == true)
{
MyImage.Source = new BitmapImage(new Uri(op.FileName));
}
}
#endregion