VideoToolTip.xaml の相互作用ロジック
Inheritance: System.Windows.Controls.UserControl
        public void InitializeToolTip(object sender, RoutedEventArgs e)
        {
            var link = sender as Hyperlink;

            //すでにツールチップがあったらスキップ
            if (link.ToolTip != null)
            {
                return;
            }

            var inline = link.Inlines.First() as Run;

            if (inline != null)
            {
                var uri = link.NavigateUri;
                //#○○:×× リンクだとnullになるので
                if (uri == null)
                {
                    var time = inline.Text;

                    if (time.StartsWith("#"))
                    {
                        link.NavigateUri = new Uri(time, UriKind.Relative);
                    }

                    return;
                }
                var text = uri.OriginalString;

                if (text.StartsWith("http://www.nicovideo.jp/watch/"))
                {
                    VideoToolTip       tooltip = new VideoToolTip();
                    VideoDataViewModel vm      = new VideoDataViewModel(text.Substring(30));
                    tooltip.DataContext = vm;
                    link.ToolTip        = tooltip;
                }
                else if (text.StartsWith("http://www.nicovideo.jp/user/"))
                {
                    UserToolTip       tooltip = new UserToolTip();
                    UserDataViewModel vm      = new UserDataViewModel(text.Substring(29));
                    tooltip.DataContext = vm;
                    link.ToolTip        = tooltip;
                }
                else if (text.StartsWith("http://www.nicovideo.jp/mylist/"))
                {
                    MylistToolTip       tooltip = new MylistToolTip();
                    MylistDataViewModel vm      = new MylistDataViewModel(text.Substring(31));
                    tooltip.DataContext = vm;
                    link.ToolTip        = tooltip;
                }
                else
                {
                    link.ToolTip = text;
                }
            }
        }
Example #2
0
        public void InitializeToolTip(object sender, RoutedEventArgs e)
        {
            var link = sender as Hyperlink;

            //すでにツールチップがあったらスキップ
            if(link.ToolTip != null) {

                return;
            }

            var inline = link.Inlines.First() as Run;
            if(inline != null) {

                var uri = link.NavigateUri;
                //#○○:×× リンクだとnullになるので
                if(uri == null) {

                    var time = inline.Text;

                    if(time.StartsWith("#")) {

                        link.NavigateUri = new Uri(time, UriKind.Relative);
                    }

                    return;
                }
                var text = uri.OriginalString;

                if(text.StartsWith("http://www.nicovideo.jp/watch/")) {

                    VideoToolTip tooltip = new VideoToolTip();
                    VideoDataViewModel vm = new VideoDataViewModel(text.Substring(30));
                    tooltip.DataContext = vm;
                    link.ToolTip = tooltip;

                } else if(text.StartsWith("http://www.nicovideo.jp/user/")) {

                    UserToolTip tooltip = new UserToolTip();
                    UserDataViewModel vm = new UserDataViewModel(text.Substring(29));
                    tooltip.DataContext = vm;
                    link.ToolTip = tooltip;

                } else if(text.StartsWith("http://www.nicovideo.jp/mylist/")) {

                    MylistToolTip tooltip = new MylistToolTip();
                    MylistDataViewModel vm = new MylistDataViewModel(text.Substring(31));
                    tooltip.DataContext = vm;
                    link.ToolTip = tooltip;

                } else {

                    link.ToolTip = text;
                }
            }
        }