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()
        {
        }

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

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

        public int total
        {
            set;
            get;
        }

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

        /// <summary>
        /// 标题
        /// </summary>
        public string title
        {
            set;
            get;
        }

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

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

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

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


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

            }
        }
lindexi_gd CSDN认证博客专家 C# WPF UWP 微软最具价值专家
我是微软Windows应用开发方向的最具价值专家,欢迎访问我博客blog.lindexi.com里面有大量WPF和UWP博客
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 终极编程指南 设计师:CSDN官方博客 返回首页