Hi,
For the command property not being called the first time when "SelectedItemsOverride" is assigned to a new "ObservableCollection", how exactly do you reproduce this ? Here's my sample that looks good :
Get more controls, features, updates and technical support with Xceed Toolkit Plus for WPF
For the command property not being called the first time when "SelectedItemsOverride" is assigned to a new "ObservableCollection", how exactly do you reproduce this ? Here's my sample that looks good :
<StackPanel>
<xctk:CheckComboBox x:Name="UserGroupsCheckedComboBox"
ItemsSource="{Binding UserGroups}"
SelectedItemsOverride="{Binding SelectedUserGroups}"
DisplayMemberPath="Name"
Command="{Binding OnUserGroupTypeToggledCommand}"
ValueMemberPath="ID" />
<StackPanel Margin="0,200,0,0"
Orientation="Horizontal">
<TextBlock Text="SelectedItems : " />
<TextBlock Text="{Binding SelectedItemsOverride.Count, ElementName=UserGroupsCheckedComboBox}" />
</StackPanel>
</StackPanel> public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.UserGroups = new ObservableCollection<MyData>()
{
new MyData() { ID = 1, Name = "First" },
new MyData() { ID = 2, Name = "Second" },
new MyData() { ID = 3, Name = "Third" },
new MyData() { ID = 4, Name = "Fourth" },
new MyData() { ID = 5, Name = "Fifth" },
};
this.SelectedUserGroups = new ObservableCollection<MyData>() { this.UserGroups[ 2 ] };
this.DataContext = this;
this.OnUserGroupTypeToggledCommand = new RelayCommand( param => SaveExecute(), param => CanExecuteMyCommand() );
}
public ICommand OnUserGroupTypeToggledCommand
{
get;
set;
}
public ObservableCollection<MyData> UserGroups
{
get;
set;
}
public ObservableCollection<MyData> SelectedUserGroups
{
get;
set;
}
private bool CanExecuteMyCommand()
{
return true;
}
public void SaveExecute()
{
System.Diagnostics.Debug.WriteLine("Saving !!");
}
}
public class MyData
{
public string Name
{
get;
set;
}
public int ID
{
get;
set;
}
}
public class RelayCommand : ICommand
{
#region Fields
readonly Action<object> _execute;
readonly Predicate<object> _canExecute;
#endregion // Fields
#region Constructors
public RelayCommand( Action<object> execute ) : this( execute, null ) { }
public RelayCommand( Action<object> execute, Predicate<object> canExecute )
{
if( execute == null )
throw new ArgumentNullException( "execute" );
_execute = execute;
_canExecute = canExecute;
}
#endregion // Constructors
#region ICommand Members
[DebuggerStepThrough]
public bool CanExecute( object parameter )
{
return _canExecute == null ? true : _canExecute( parameter );
}
public event EventHandler CanExecuteChanged
{
add
{
CommandManager.RequerySuggested += value;
}
remove
{
CommandManager.RequerySuggested -= value;
}
}
public void Execute( object parameter )
{
_execute( parameter );
}
#endregion // ICommand Members
}――――
Get more controls, features, updates and technical support with Xceed Toolkit Plus for WPF