Slider ValueChanged 方法命令(MVVM WPF Devexpress)

Slider ValueChanged method command ( MVVM WPF Devexpress )

我正在尝试将方法绑定到滑块的更改值。 我正在使用 devexpress poco,

XAML:

<ListView.ItemTemplate>
     <DataTemplate>
          <StackPanel Height="140" Margin="20">
               <Slider Height="100" Width="40" Margin="5" HorizontalAlignment="Left" TickFrequency="10" TickPlacement="BottomRight" Orientation="Vertical" Minimum="0" Maximum="100" Value="{Binding VolumeLevel}">
                    <dxmvvm:Interaction.Behaviors>
                         <dxmvvm:EventToCommand EventName="ValueChanged" Command="{Binding Path=VolumeChangedCommand}" />
                    </dxmvvm:Interaction.Behaviors>
               </Slider>
               <TextBlock Text="{Binding Name}" />
          </StackPanel>
     </DataTemplate>
</ListView.ItemTemplate>

我的 C# 代码:

public void VolumeChanged()
{
     ...
}

该方法从未被调用。
有什么建议么?

因为您将滑块绑定到 Command(这一行:<dxmvvm:EventToCommand EventName="ValueChanged" Command="{Binding Path=VolumeChangedCommand}" />),而您没有 Command,所以它不会触发。您需要做的就是添加一个 public Command VolumeChangedCommand

private ICommand _VolumeChangedCommand;
public ICommand VolumeChangedCommand
{
    get
    {
        if (_VolumeChangedCommand == null)
            _VolumeChangedCommand = new CommandImplement();
        return _VolumeChangedCommand ;
    }
    set
    {
        _VolumeChangedCommand = value;
    }
}

class CommandImplement: ICommand
{
    public bool CanExecute(object parameter)
    {
        return true;
    } 
    public event EventHandler CanExecuteChanged
    {
        add { CommandManager.RequerySuggested += value; }
        remove { CommandManager.RequerySuggested -= value; }
    } 

    public void Execute(object parameter)
    {
         VolumeChanged(); //Call your method or put your code here.
    }
}