WPF DataGridHyperlinkColumn

为了点击链接,我们使用

                    <DataGrid x:Name="data" LoadingRow="load"  ItemsSource="{Binding Path=pull_gmc,Mode=TwoWay}" CanUserDeleteRows="True" AutoGenerateColumns="False" CanUserSortColumns="True">
                        <DataGrid.Columns >                            
                            <DataGridHyperlinkColumn Header="产品链接" ContentBinding="{Binding Path=prond}" Binding="{Binding Path=productId}">
                                <DataGridHyperlinkColumn.ElementStyle>
                                    <Style TargetType="TextBlock">
                                        <EventSetter Event="Hyperlink.Click" HandledEventsToo="False" Handler="url">EventSetter>
                                        --<EventSetter Event="MouseLeftButtonDown" Handler="url">EventSetter>-->
                                    Style>
                                DataGridHyperlinkColumn.ElementStyle>
                            DataGridHyperlinkColumn>
                        DataGrid.Columns>
                    DataGrid>
    public class gmccolleague
    {
        public gmccolleague()
        {
        }

        /// 
        /// 产品链接
        /// 
        public string productId
        {
            set;
            get;
        }

        public static string prond
        {
            set;
            get;
        } = "产品链接";

        public int total
        {
            set;
            get;
        }

        /// 
        /// 关键字
        /// 
        public string primary
        {
            set;
            get;
        }

        /// 
        /// 标题
        /// 
        public string title
        {
            set;
            get;
        }

        /// 
        /// 产品类别
        /// 
        public string leaf_cat_name
        {
            set;
            get;
        }

        /// 
        /// 使用次数
        /// 
        public int count
        {
            set;
            get;
        }

        /// 
        /// 质量得分
        /// 
        public string iq_score
        {
            set;
            get;
        }
    }

        public ObservableCollection pull_gmc
        {
            set;
            get;
        } = new ObservableCollection();


        private void url(object sender, RoutedEventArgs e)
        {
            try
            {
                Uri destination = ((Hyperlink)e.OriginalSource).NavigateUri;
                Process.Start("http://" + destination.ToString());
            }
            catch 
            {

            }
        }

你可能感兴趣的:(WPF,#,WPF,开发)