Click here to Skip to main content
15,911,530 members
Home / Discussions / WPF
   

WPF

 
QuestionWPF editor is duplicating my image files Pin
tbenner196016-Dec-22 4:54
tbenner196016-Dec-22 4:54 
AnswerRe: WPF editor is duplicating my image files Pin
Dave Kreskowiak16-Dec-22 11:32
mveDave Kreskowiak16-Dec-22 11:32 
GeneralRe: WPF editor is duplicating my image files Pin
tbenner196017-Dec-22 3:27
tbenner196017-Dec-22 3:27 
GeneralRe: WPF editor is duplicating my image files Pin
Dave Kreskowiak17-Dec-22 5:25
mveDave Kreskowiak17-Dec-22 5:25 
QuestionCustomizing the TabPanel section of the TabControl (simple solution found) Pin
Maximilien15-Dec-22 4:33
Maximilien15-Dec-22 4:33 
QuestionWPF .Net Core Dependency Injection & View Models Pin
Kevin Marois14-Dec-22 12:06
professionalKevin Marois14-Dec-22 12:06 
AnswerRe: WPF .Net Core Dependency Injection & View Models Pin
Graeme_Grant31-Dec-22 3:15
mvaGraeme_Grant31-Dec-22 3:15 
Question(ANSWERED) (newbie) I'm confused about ListView ItemSource bindings. Pin
Maximilien8-Dec-22 2:42
Maximilien8-Dec-22 2:42 
AnswerRe: (newbie) I'm confused about ListView ItemSource bindings. Pin
Richard Deeming8-Dec-22 3:58
mveRichard Deeming8-Dec-22 3:58 
GeneralRe: (newbie) I'm confused about ListView ItemSource bindings. Pin
Maximilien8-Dec-22 4:22
Maximilien8-Dec-22 4:22 
Questionfast directory infos for a lot of files Pin
pitwi6-Dec-22 2:14
pitwi6-Dec-22 2:14 
AnswerRe: fast directory infos for a lot of files Pin
pitwi6-Dec-22 2:29
pitwi6-Dec-22 2:29 
GeneralRe: fast directory infos for a lot of files Pin
Dave Kreskowiak6-Dec-22 5:40
mveDave Kreskowiak6-Dec-22 5:40 
AnswerRe: fast directory infos for a lot of files Pin
Richard Deeming6-Dec-22 2:51
mveRichard Deeming6-Dec-22 2:51 
GeneralRe: fast directory infos for a lot of files Pin
pitwi6-Dec-22 6:56
pitwi6-Dec-22 6:56 
QuestionCustom Control Styling Pin
Kevin Marois2-Dec-22 8:58
professionalKevin Marois2-Dec-22 8:58 
AnswerRe: Custom Control Styling Pin
Richard Deeming5-Dec-22 0:27
mveRichard Deeming5-Dec-22 0:27 
GeneralRe: Custom Control Styling Pin
Kevin Marois5-Dec-22 12:15
professionalKevin Marois5-Dec-22 12:15 
GeneralRe: Custom Control Styling Pin
Richard Deeming5-Dec-22 21:57
mveRichard Deeming5-Dec-22 21:57 
GeneralRe: Custom Control Styling Pin
Kevin Marois5-Dec-22 13:57
professionalKevin Marois5-Dec-22 13:57 
GeneralRe: Custom Control Styling Pin
Kevin Marois5-Dec-22 14:10
professionalKevin Marois5-Dec-22 14:10 
QuestionWPF .Net Core Relay Command with Parameters Pin
Kevin Marois1-Dec-22 13:50
professionalKevin Marois1-Dec-22 13:50 
QuestionForgot Password Pin
Kevin Marois1-Dec-22 13:06
professionalKevin Marois1-Dec-22 13:06 
AnswerRe: Forgot Password Pin
Richard Deeming1-Dec-22 22:10
mveRichard Deeming1-Dec-22 22:10 
QuestionWPF Core Hyperlkink Custom Control Pin
Kevin Marois29-Nov-22 16:29
professionalKevin Marois29-Nov-22 16:29 
I'm trying to create what I thought would be a simple custom control to implement a hyperlink.

This all works in WPF .Net Framework, but in .Net Core I have 2 problems. First, here's the code:

XAML
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:MaroisHyperlink"
                    xmlns:i="http://schemas.microsoft.com/xaml/behaviors">

<pre>
<Style TargetType="{x:Type local:MaroisHyperlink}">

    <Setter Property="Template">

        <Setter.Value>

            <ControlTemplate>

                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">

                    <TextBlock>

                        <Hyperlink>

                             <TextBlock Text="{Binding LinkText}"/>

                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <i:InvokeCommandAction Command="{Binding LinkClickedCommand}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>

                        </Hyperlink>

                    </TextBlock>

                </Border>

            </ControlTemplate>

        </Setter.Value>

    </Setter>

</Style>




Code Behind

using Marois.Framework.Core.Utilities;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace MaroisHyperlink
{
    public class MaroisHyperlink : Control
    {
        #region Commands
        private ICommand? _LinkClickedCommand;
        public ICommand LinkClickedCommand
        {
            get
            {
                if (_LinkClickedCommand == null)
                    _LinkClickedCommand = new RelayCommand(LinkClickedExecuted, LinkClickedCanExecute);
                return _LinkClickedCommand;
            }
        }
        #endregion

        #region DP LinkText
        public static readonly DependencyProperty LinkTextProperty =
                    DependencyProperty.Register("LinkText",
                    typeof(string),
                    typeof(MaroisHyperlink),
                    new PropertyMetadata("", new PropertyChangedCallback(OnLinkTextChanged)));

        public string LinkText
        {
            get { return (string)GetValue(LinkTextProperty); }
            set { SetValue(LinkTextProperty, value); }
        }

        private static void OnLinkTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //var control = (MaroisHyperlink)d;
        }
        #endregion

        #region LinkClickedEvent
        public static readonly RoutedEvent LinkClickedEvent =
                    EventManager.RegisterRoutedEvent("LinkClicked",
                    RoutingStrategy.Bubble,
                    typeof(RoutedEventHandler),
                    typeof(MaroisHyperlink));

        public event RoutedEventHandler LinkClicked
        {
            add { AddHandler(LinkClickedEvent, value); }
            remove { RemoveHandler(LinkClickedEvent, value); }
        }

        private void RaiseLinkClickedEvent()
        {
            RaiseEvent(new RoutedEventArgs(LinkClickedEvent));
        }
        #endregion

        #region CTOR
        static MaroisHyperlink()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MaroisHyperlink),
                new FrameworkPropertyMetadata(typeof(MaroisHyperlink)));
        }
        #endregion

        #region Private Methods
        private bool LinkClickedCanExecute()
        {
            return IsEnabled;
        }

        private void LinkClickedExecuted()
        {
            RaiseLinkClickedEvent();
        }
        #endregion
    }
}

Window

<Window x:Class="HyperlinkDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:link="clr-namespace:MaroisHyperlink;assembly=MaroisHyperlink"
        WindowStartupLocation="CenterScreen"
        mc:Ignorable="d"
        Title="MainWindow" 
        Height="300" 
        Width="500">

<pre>
<Grid>

    <link:MaroisHyperlink LinkText="Click This Link!"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Center"
                          FontSize="16"/>

</Grid>




Problems

1. The LinkText is not appearing. I get no binding errors, but when I run it, there's nothing showing. If I set the inner TextBox's text to something, then it shows up.
<TextBlock>

<pre>
<Hyperlink>

    <TextBlock Text="THIS SHOWS UP"/>

</Hyperlink>



2. This doesn't compile:
<i:Interaction.Triggers>
    <i:EventTrigger EventName="Click">
        <i:InvokeCommandAction Command="{Binding LinkClickedCommand}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>
I get
The type 'Interaction' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
I have package "Microsoft.Xaml.Behaviors.WPF (1.1.39") installed and my namespace is "xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.