Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Combobox trong WPF và mô hình MVVM

6 năm trước 589 lượt xem 1 bình luận 6 năm trước

Mình muốn sử dụng event SelectionChanged của combobox trong MVVM. mình dùng cách của Kteam. mình chẳng hiểu sao mà lúc chạy thì nó bỏ qua command của event selectionChanged ạ. ai giúp mình mới. 

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
Devil Night đã bình luận 6 năm trước

<i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding SelectedChangedCommand}" CommandParameter="{Binding ElementName=cbxCategory,Path=SelectedItem}"/>
        </i:EventTrigger>
</i:Interaction.Triggers>

<ComboBox materialDesign:HintAssist.Hint="Category" Margin="5" x:Name="cbxCategory" SelectedItem ="{Binding SelectedCategory}" Style="{StaticResource MaterialDesignFloatingHintComboBox}">
                <ComboBoxItem Content="1"/>
                <ComboBoxItem Content="2"/>

</ComboBox>

 SelectedChangedCommand = new RelayCommand<object>((p)=> { return true; }, (p)=> { 
                MessageBox.Show("Hello World");
                
            });

Câu hỏi mới nhất