UserControl2.xaml.cs 1.2 KB
using System;
using System.Collections;
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 SmartScan.SetControl.WPF
{
    /// <summary>
    /// UserControl2.xaml 的交互逻辑
    /// </summary>
    public partial class UserControl2 : UserControl
    {
        public UserControl2()
        {
            InitializeComponent();
        }

        // 公开获取data3控件的方法
        public ListView GetListView()
        {
            return data3;
        }

        // 提供设置ItemsSource的方法
        public void SetItemsSource(IEnumerable source)
        {
            data3.ItemsSource = source;
        }

        // 暴露选中索引改变的事件
        public event SelectionChangedEventHandler SelectionChanged;

        private void data3_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // 触发外部事件
            SelectionChanged?.Invoke(sender, e);
        }
    }

}