Click here to Skip to main content
15,860,972 members
Home / Discussions / C#
   

C#

 
GeneralRe: I have requirement to compare two list or any container which is feasible for the requirement in C#.net Pin
Eddy Vluggen30-Jun-16 4:21
professionalEddy Vluggen30-Jun-16 4:21 
GeneralRe: I have requirement to compare two list or any container which is feasible for the requirement in C#.net Pin
Jim_Snyder30-Jun-16 4:27
professionalJim_Snyder30-Jun-16 4:27 
GeneralRe: I have requirement to compare two list or any container which is feasible for the requirement in C#.net Pin
Eddy Vluggen30-Jun-16 7:58
professionalEddy Vluggen30-Jun-16 7:58 
GeneralRe: I have requirement to compare two list or any container which is feasible for the requirement in C#.net Pin
Jim_Snyder1-Jul-16 3:13
professionalJim_Snyder1-Jul-16 3:13 
GeneralRe: I have requirement to compare two list or any container which is feasible for the requirement in C#.net Pin
Jim_Snyder30-Jun-16 4:33
professionalJim_Snyder30-Jun-16 4:33 
Questionhow to fire up the message receive handler on runtime? Pin
Member 1255232425-Jun-16 23:46
Member 1255232425-Jun-16 23:46 
AnswerRe: how to fire up the message receive handler on runtime? Pin
OriginalGriff26-Jun-16 1:13
mveOriginalGriff26-Jun-16 1:13 
QuestionCommand Binding Pin
Member 1245711024-Jun-16 3:46
Member 1245711024-Jun-16 3:46 
I have followed Josh Smith's article "Patterns - WPF Apps with the Model-View-ViewModel Design Pattern" , and examples in two books. But I still don't see what is going on in my attempt to bind a Command to a ViewModel.
In my XAML I have:
HTML
<Window x:Class="Samples.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:Samples.ViewModel"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interctivity"
        Title="MainWindow" Style="{StaticResource styWindow}">

    <Window.DataContext>
        <vm:LabTechViewModel />
    </Window.DataContext>

    <Window.Resources>
        
        <DataTemplate x:Key="techData">
            <Border Margin="2"
                BorderThickness="2"
                CornerRadius="4"
                BorderBrush="SteelBlue" 
                    HorizontalAlignment="Stretch">
                <Grid ShowGridLines="False" HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Text="{Binding TechID}">
                    </TextBlock>
                    <TextBlock Grid.Row="1" Text="{Binding TechName}" FontWeight="Bold">
                    </TextBlock>
                </Grid>
            </Border>
        </DataTemplate>
        
        <DataTemplate x:Key="progBar">
            <Border BorderThickness="2"
                    BorderBrush="Blue"
                    CornerRadius="4"
                    HorizontalAlignment="Stretch">
                <Grid>
                <ProgressBar HorizontalAlignment="Stretch"
                             VerticalAlignment="Stretch"
                             Minimum="{Binding Minimum}"
                             Maximum="{Binding Maximum}"
                             Value="{Binding ProgressValue}"/>
                <Button x:Name="progButton"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    Command="{Binding ProgressCommand}"
                    Content="{Binding ProgressButtonContent, FallbackValue='Bite Me'}"
                    Background="Transparent" />
                </Grid>             
            </Border>
        </DataTemplate>
        
    </Window.Resources>

    <Grid ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel>

            <ComboBox x:Name="lstOperators"
                    HorizontalAlignment="Stretch"
                    HorizontalContentAlignment="Stretch"
                    ItemsSource="{Binding LabTechs}"
                    ItemTemplate="{StaticResource techData}"
                    SelectedItem="{Binding LabTechSelected}"
                    SelectedIndex="0"
                    >
            </ComboBox>
            
            <ContentControl ContentTemplate="{StaticResource progBar}"
                            >
                
            </ContentControl>


        </StackPanel>
    </Grid>
</Window>


An I have this in my ViewModel. Some of the ViewModel has been left out for brevity.
C#
//This is the constructor
        public LabTechViewModel()
        {
            _techList = DataAccess.GetAllLabTechs();
            _progressCommand = new RelayCommand(param => this.OnProgressClicked());
        }

        private RelayCommand _progressCommand;
        public ICommand ProgressCommand
        {
            get
            {
                if (_progressCommand == null)
                    _progressCommand = new RelayCommand(param => this.OnProgressClicked());

                return _progressCommand;
            }
        }

        void OnProgressClicked()
        {
            if (_progButtonContent == "Stopped, Click to Start")
            {
                //Start the Comm scan 
                _progButtonContent = "Scanning, click to stop";
                RaisePropertyChanged("ProgressButtonContent");
                RaisePropertyChanged("ProgressMaximum");
                RaisePropertyChanged("ProgerssMinimum");
            }
        }


And I have this RelayCommand Class that was repeated in the book examples. I am including the entire class here.

C#
class RelayCommand : ICommand
{
    readonly Action<object> _execute;
    readonly Predicate<object> _canExecute;

    public RelayCommand(Action<object> execute, Predicate<object> canExecute)
    {
        if (execute == null) throw new ArgumentNullException("execute");

        _execute = execute;
        _canExecute = canExecute;
    }

    public RelayCommand(Action<object> execute) : this(execute, null) { }

    public bool CanExecute(object parameters)
    {
        return _canExecute == null ? true : _canExecute(parameters);
    }

    public event EventHandler CanExecuteChanged
    {
        add { CommandManager.RequerySuggested += value; }
        remove { CommandManager.RequerySuggested -= value; }
    }

    public void Execute(object parameters)
    {
        _execute(parameters);
    }
}


It appears that I am missing the magic link. I have a break point set at the ICommand ProgressCommand property and it never gets hit.
AnswerRe: Command Binding Pin
Gerry Schmitz24-Jun-16 4:21
mveGerry Schmitz24-Jun-16 4:21 
AnswerRe: Command Binding Pin
Bernhard Hiller26-Jun-16 21:11
Bernhard Hiller26-Jun-16 21:11 
AnswerRe: Command Binding Pin
Pete O'Hanlon26-Jun-16 22:00
subeditorPete O'Hanlon26-Jun-16 22:00 
QuestionDataGridViewCheckBoxColumn Checkig Problem Pin
Member 1209010423-Jun-16 20:17
Member 1209010423-Jun-16 20:17 
SuggestionRe: DataGridViewCheckBoxColumn Checkig Problem Pin
CHill6024-Jun-16 0:10
mveCHill6024-Jun-16 0:10 
Questionwhy extension method is required in c#? Pin
Member 1031806523-Jun-16 18:36
Member 1031806523-Jun-16 18:36 
AnswerRe: why extension method is required in c#? Pin
PIEBALDconsult23-Jun-16 18:40
mvePIEBALDconsult23-Jun-16 18:40 
AnswerRe: why extension method is required in c#? PinPopular
OriginalGriff23-Jun-16 20:40
mveOriginalGriff23-Jun-16 20:40 
GeneralRe: why extension method is required in c#? Pin
PIEBALDconsult24-Jun-16 3:35
mvePIEBALDconsult24-Jun-16 3:35 
QuestionUse one dimensional array with RDotNet in C# Pin
Member 1085025323-Jun-16 8:30
Member 1085025323-Jun-16 8:30 
QuestionUpdate SQL table using CLR Pin
IT - Researcher22-Jun-16 21:38
IT - Researcher22-Jun-16 21:38 
QuestionRe: Update SQL table using CLR Pin
Gerry Schmitz23-Jun-16 12:44
mveGerry Schmitz23-Jun-16 12:44 
AnswerRe: Update SQL table using CLR Pin
IT - Researcher23-Jun-16 18:56
IT - Researcher23-Jun-16 18:56 
GeneralRe: Update SQL table using CLR Pin
Gerry Schmitz24-Jun-16 3:44
mveGerry Schmitz24-Jun-16 3:44 
QuestionProgrammatically Change Windows Photo View Language Pin
Kevin Marois22-Jun-16 13:24
professionalKevin Marois22-Jun-16 13:24 
AnswerMessage Closed Pin
22-Jun-16 20:23
Member 1259925622-Jun-16 20:23 
GeneralRe: Programmatically Change Windows Photo View Language Pin
Pete O'Hanlon22-Jun-16 21:31
subeditorPete O'Hanlon22-Jun-16 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.