在视图加载期间避免下拉选择更改事件

时间:2015-11-12 05:39:17

标签: wpf

网格包含下拉控件。我希望在视图加载期间避免选择更改事件。实现这一目标的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

我不知道WPF中的dropdown控件是什么

我已尝试使用combobox SelectionChanged 事件未在表单加载时触发

这是我的代码

<Window x:Class="Q6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Q6"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ComboBox SelectionChanged="ComboBox_SelectionChanged"
                  Height="30" Width="100">
            <ComboBoxItem>Alpha</ComboBoxItem>
            <ComboBoxItem>Beta</ComboBoxItem>
            <ComboBoxItem>Gamma</ComboBoxItem>
        </ComboBox>
    </Grid>
</Window>

代码隐藏:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Q6
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
             //Not firing at load time
        }
    }
}