[WPF - C7] - Problem with datagridview

BlackSun 21 Reputation points

I have a datagrid and when I drag fastly the vertical scroll bar to the bottom it shows like that

If I click on "Install" (it's a datagrid cell with a button inside), it doesn't work and I get that

If now I click on "Install" it works... but it's not what i want!

How can I fix this problem?
I would like the button start immediatly.

Thank you very much

Cheers, Blacksun

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,316 Reputation points

    Hi, I cannot reproduce your problem without additional information. Try following Demo:

    <Window x:Class="WpfApp1.Window34"
            Title="Window34" Height="450" Width="800">
        <local:ViewModel x:Key="vm"/>
      <Grid DataContext="{StaticResource vm}">
        <DataGrid ItemsSource="{Binding View}" AutoGenerateColumns="False">
            <DataGridTemplateColumn Header="Button">
                  <Button Content="{Binding Col1}" 
                          Command="{Binding Cmd, Source={StaticResource vm}}" 
                          CommandParameter="{Binding Col2}"/>
            <DataGridTextColumn Header="Col1" Binding="{Binding Col1}"/>
            <DataGridTextColumn Header="Col2" Binding="{Binding Col2}"/>


    using System;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Input;
    namespace WpfApp34
      public class ViewModel
        public ViewModel()
          ObservableCollection<Data> col = new ObservableCollection<Data>();
          for (int i = 0; i < 10; i++) col.Add(new Data() { Col1=$"Row {i}", Col2=$"Data {i}"});
          cvs.Source = col;
        public ICollectionView View { get => cvs.View; }
        private CollectionViewSource cvs = new CollectionViewSource();
        public ICommand Cmd { get => new RelayCommand((state) => Debug.WriteLine(state.ToString())); }
      public class Data
        public string Col1 { get; set; }
        public string Col2 { get; set; }
      public class RelayCommand : ICommand
        private readonly Predicate<object> _canExecute;
        private readonly Action<object> _action;
        public RelayCommand(Action<object> action) : this(action, null) { }
        public RelayCommand(Action<object> action, Predicate<object> canExecute) { _action = action; _canExecute = canExecute; }
        public void Execute(object o) => _action(o);
        public bool CanExecute(object o) => _canExecute == null ? true : _canExecute(o);
        public event EventHandler CanExecuteChanged
          add { CommandManager.RequerySuggested += value; }
          remove { CommandManager.RequerySuggested -= value; }
    0 comments No comments