Tags down


WPF MVVM : Calling a method in view model from a converter

By : Iñigo Cañedo
Date : October 16 2020, 03:08 PM
Any of those help I have a WPF image control which its source property is bound to a property that returns an image. , You could use a multi-converter that accepts several values:
code :
public class ImgToSrcConverter : IMultiValueConverter
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        Image image = values[0] as Image;
        if (image != null)
            MemoryStream ms = new MemoryStream();
            image.Save(ms, image.RawFormat);
            ms.Seek(0, SeekOrigin.Begin);
            BitmapImage bi = new BitmapImage();
            bi.StreamSource = ms;

            ViewModel vm = values[1] as ViewModel;
            bi.DownloadCompleted += (s, e) => 

            return bi;
        return null;

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        throw new NotImplementedException();
<Image Grid.Row="0">
        <MultiBinding NotifyOnTargetUpdated="True" Converter="{StaticResource imgToSrcConverter}">
            <Binding Path="ImageSrc" />
            <Binding Path="." />

Share : facebook icon twitter icon

Is it possible execute a method in the view when a property changes in the view model, with MVVM pattern?

By : Person123
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Álvaro García
The simplest and IMO the best way to do this is to accept an ICommand in your ViewModel from the controller.
code :
public class ViewController
    private View _view;
    private ViewModel _viewModel;

    public ViewController()
        ICommand closeView = new DelegateCommand(m => closeView());
        this._view = new View();
        this._viewModel = new ViewModel(closeView);
        this._view.DataContext = this._viewModel;

    private void closeView()

public class ViewModel
    private bool _viewModelClosing;

    public ICommand CloseView { get;set;}

    public bool ViewModelClosing
        get { return this._viewModelClosing; }
            if (value != this._viewModelClosing)
                this._viewModelClosing = value;
                // odd to do it this way.
                // better bind a button event in view 
                // to the ViewModel.CloseView Command


    public ViewModel(ICommand closeCommand)
        this.CloseView = closeCommand;

Does calling View Model methods in Code Behind events break the MVVM?

By : stacey
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Nope, this is perfectly fine.
It's the View's job to handle user input and interact with the ViewModel. A button click event-handler, which calls a method of the ViewModel in response, falls quite cleanly into this role.

Calling method from view in model on model instance, rails?

By : user7417697
Date : March 29 2020, 07:55 AM
hope this fix your issue Without passing a method explicitly to an object, it is passed to self, which in a view means a view instance. So you need to pass your method to a Micropost instance instead (e.g. @micropost.sanitized_gif_url). Its method definition also has some errors too:
code :
##micropost in micropost.gif_url is undefined. you can use self.gif_url or just gif_url, as self is implied. 
##I'd remove "self.gif_url =" too unless this is used in a callback to sanitize url before saving
  def sanitized_gif_url
    self.gif_url = Sanitize.fragment(gif_url, elements etc to sanitize here).html_safe
def sanitized_gif_url(url)
  Sanitize.fragment(url, elements etc to sanitize here).html_safe

## _micropost.html.erb
<%= sanitized_gif_url(@micropost.gif_url) %>

MVVM: How to call method on view from view model?

By : Meghana
Date : March 29 2020, 07:55 AM

Wpf MVVM button call method in view and view model also

By : Speecduber
Date : March 29 2020, 07:55 AM
To fix the issue you can do In my MVVM application a have a button in a view. When I press a button I want the run some method in the view, and also some method in the view model. I connected come command to my button, so the command can run some method in the view model. But how can I run some method in view also? I tried to connect a click event also, but it does not work. What is the best way to run functions from view and viewmodel also. , You can do this entirely in XAML with interaction triggers:
Related Posts Related Posts :
  • Cannot display Fetched JSON data from Web API call since backslashes are in response
  • C# - Responsive Winforms application positioning of pictureboxes
  • How to wait for response from NamedPipeServer?
  • What's the user parameter to PasswordHasher's methods used for?
  • How to show an exception message if the user doesn't check a radio button in Xamarin Android?
  • Left Align UICollectionView Cell When it has one item in Xamarin.ios
  • Entity Framework Core - First returning duplicate results after migrating to .net core
  • LINQ Query to put data in a nested object
  • Chart bind to non-primitive type
  • ASP.NET Core 2 - global filters registration multiple ways?
  • How do i get my check boxes to display and add numbers into a label on C#
  • IIS Express bad hostname android studio
  • Combining Frames of a Tiff into a single png gives Out of Memory Exception C#
  • Return HTML from ASP.NET Web API ASP.NET Core 2 and get http status 406
  • When inheriting a base class, is there a reason why C# defaults to new instead of override?
  • Simulator mode hangs at Registering the application to run from layout
  • Multiple ExpectedException in MsTest
  • JSON Differing names
  • Keeping hexadecimal characters of a xml file unchanged after save?
  • How do you test Azure Queue trigger functions locally?
  • OfficeOpenXML excel Resize rows with cells merged across them
  • Get the length of jsonResults.Data in C#
  • Does Stopwatch have a maximum time it can run?
  • How do you add two values into a list as one key? C#
  • How can I UPDATE specific GridView columns based on a CheckBox in one column
  • Delete where in clause in sqlite
  • MSBuild failing. Missing Release/WinRTXamlToolkit
  • binding an asp.net checkbox on serverside
  • WPF Datagrid Column Visibility not working with MultiBinding
  • Why am I getting error CS0116 when building using a .rsp file?
  • OpenFileDialog on .NET Core
  • c# - Auto increment in sqlite stops at number 10
  • How to access specific controls in a ASP.Net Repeater
  • Is it possible to use a file upload control to upload only image and video type of file at one time?
  • Linq left joining 3 tables
  • Bind UI values to object instance of model in WPF
  • C# beginner - Callback in the same function
  • Outlook AddIn for filtering recipients
  • C# web form - Looking to get the date of the first monday of the month after the selected date from the calendar
  • C# tcp async listener gets stuck on my on_receive callback after client closes socket
  • For Input.Gettouch(0).phase==TouchPhase.Moved , How to store all touch positions in a array?
  • WPF, Telerik: Change control style when disabled
  • Publishing a .NET Core / Angular 4 Project to Netlify
  • Exclude folder in ASP.NET Core 2
  • Binding background of datatemplate in contentcontrol
  • How to access inner stringified JSON data using JavaScriptSerializer
  • Creating COM interface pointer in DLL method works when called from one application but does not when called from anothe
  • C# post chunks of ids and merge response using async and await
  • Event initialization on declaration
  • How to validate a DbType.Guid as a Valid Parameter before calling a stored procedure?
  • Weird symbols instead of cyrillic
  • C# Windiws IoT core - Display and Scroll text in Textblock over an Image Grid
  • UpdateDriverForPlugAndPlayDevices throws AccessViolationException
  • Getting a value type from binary file c#
  • simple streamwriter not writing
  • How i use array of vector3 to list in inspector all vector3 in list?
  • Dropbox API 2 - UploadAsync returns invalid path error
  • c#- Can't delete multi rows in datagridview with sqlite database
  • resize datagrid based on a screen resolution
  • .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com