Click here to Skip to main content
15,559,491 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: (newbie) I'm confused about ListView ItemSource bindings. Pin
Richard Deeming8-Dec-22 4:58
mveRichard Deeming8-Dec-22 4:58 
GeneralRe: (newbie) I'm confused about ListView ItemSource bindings. Pin
Maximilien8-Dec-22 5:22
Maximilien8-Dec-22 5:22 
Questionfast directory infos for a lot of files Pin
pitwi6-Dec-22 3:14
pitwi6-Dec-22 3:14 
AnswerRe: fast directory infos for a lot of files Pin
pitwi6-Dec-22 3:29
pitwi6-Dec-22 3:29 
GeneralRe: fast directory infos for a lot of files Pin
Dave Kreskowiak6-Dec-22 6:40
mveDave Kreskowiak6-Dec-22 6:40 
AnswerRe: fast directory infos for a lot of files Pin
Richard Deeming6-Dec-22 3:51
mveRichard Deeming6-Dec-22 3:51 
GeneralRe: fast directory infos for a lot of files Pin
pitwi6-Dec-22 7:56
pitwi6-Dec-22 7:56 
QuestionCustom Control Styling Pin
Kevin Marois2-Dec-22 9:58
professionalKevin Marois2-Dec-22 9:58 
I have created a Hyperlink control. What I want is to have a default style in my control itself, but allow consumers to restyle it later, like when It's dropped into a window.

So here's my control's XAML:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Marois.Framework.Core.WPF.Controls"
                    xmlns:i="http://schemas.microsoft.com/xaml/behaviors">

    <SolidColorBrush x:Key="hyperlinkMouseOverBrush" Color="Green"/>

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

        <Setter Property="FontSize" Value="60" />
        <Setter Property="Hyperlink.TextDecorations" Value="None" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate>

                    <TextBlock>

                            <Hyperlink>

                                <TextBlock Text="{Binding LinkText, RelativeSource={RelativeSource TemplatedParent}}"
                                           FontSize="{TemplateBinding FontSize}"/>

                            </Hyperlink>

                        </TextBlock>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

        <Style.Triggers>

            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Hyperlink.Foreground" Value="{StaticResource hyperlinkMouseOverBrush}" />
                <Setter Property="Hyperlink.TextDecorations" Value="Underline" />
            </Trigger>

            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Hyperlink.Foreground" Value="Gray" />
                <Setter Property="Hyperlink.TextDecorations" Value="None" />
            </Trigger>

        </Style.Triggers>

    </Style>

</ResourceDictionary>
Code behind:
using System.Windows;
using System.Windows.Media;

namespace Marois.Framework.Core.WPF.Controls
{
    public class MaroisHyperlink : ControlBase
    {
        #region DP's
        #region DP HoverBrush
        public static readonly DependencyProperty HoverBrushProperty =
                    DependencyProperty.Register("HoverBrush",
                    typeof(SolidColorBrush),
                    typeof(MaroisHyperlink),
                    new PropertyMetadata(new SolidColorBrush(Colors.Black)));

        public SolidColorBrush HoverBrush
        {
            get { return (SolidColorBrush)GetValue(HoverBrushProperty); }
            set { SetValue(HoverBrushProperty, value); }
        }
        #endregion

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

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

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

        }
        #endregion
    }
}
Some of this works:
- LinkText DP works. I can set it's default value and that shows up when I put the control on the window. Changing it in the window works also
- The FontSize setter at the top works.
- The Hyperlink.TextDecorations does not.
- None of the triggers at the bottom work.

In the Window
<Window x:Class="Marois.Framework.Core.WPF.Controls.Demo.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:i="http://schemas.microsoft.com/xaml/behaviors"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:marois="clr-namespace:Marois.Framework.Core.WPF.Controls;assembly=Marois.Framework.Core.WPF.Controls"
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen"
        Title="MainWindow" 
        Height="450" 
        Width="800">

    <Window.Resources>

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

            <Setter Property="Foreground" Value="DarkTurquoise"/>
            <Setter Property="HoverBrush" Value="Brown"/>
            <Setter Property="FontSize" Value="18"/>

        </Style>

    </Window.Resources>

    <Grid>

        <marois:MaroisHyperlink Grid.Row="0" 
                                Grid.Column="0"
                                LinkText="Click me!"
                                Margin="5">

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

        </marois:MaroisHyperlink>

    </Grid>

</Window>
In the style
- The FontSize works
- The HoverBrush does not work
- The Foreground does not work

So basically I can style the FontSize, but nothing else. I'm not really sure how to make this all work. I'd like it to be like any other 3rd party control - Have default values that you can restyle.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Custom Control Styling Pin
Richard Deeming5-Dec-22 1:27
mveRichard Deeming5-Dec-22 1:27 
GeneralRe: Custom Control Styling Pin
Kevin Marois5-Dec-22 13:15
professionalKevin Marois5-Dec-22 13:15 
GeneralRe: Custom Control Styling Pin
Richard Deeming5-Dec-22 22:57
mveRichard Deeming5-Dec-22 22:57 
GeneralRe: Custom Control Styling Pin
Kevin Marois5-Dec-22 14:57
professionalKevin Marois5-Dec-22 14:57 
GeneralRe: Custom Control Styling Pin
Kevin Marois5-Dec-22 15:10
professionalKevin Marois5-Dec-22 15:10 
QuestionWPF .Net Core Relay Command with Parameters Pin
Kevin Marois1-Dec-22 14:50
professionalKevin Marois1-Dec-22 14:50 
QuestionForgot Password Pin
Kevin Marois1-Dec-22 14:06
professionalKevin Marois1-Dec-22 14:06 
AnswerRe: Forgot Password Pin
Richard Deeming1-Dec-22 23:10
mveRichard Deeming1-Dec-22 23:10 
QuestionWPF Core Hyperlkink Custom Control Pin
Kevin Marois29-Nov-22 17:29
professionalKevin Marois29-Nov-22 17:29 
AnswerRe: WPF Core Hyperlkink Custom Control Pin
Richard Deeming29-Nov-22 22:59
mveRichard Deeming29-Nov-22 22:59 
GeneralRe: WPF Core Hyperlkink Custom Control Pin
Kevin Marois30-Nov-22 6:46
professionalKevin Marois30-Nov-22 6:46 
GeneralRe: WPF Core Hyperlkink Custom Control Pin
Richard Deeming30-Nov-22 22:25
mveRichard Deeming30-Nov-22 22:25 
QuestionPath Images Pin
Kevin Marois29-Nov-22 15:57
professionalKevin Marois29-Nov-22 15:57 
AnswerRe: Path Images Pin
Richard Deeming30-Nov-22 0:46
mveRichard Deeming30-Nov-22 0:46 
QuestionDropShadowEffect Above & Below Pin
Kevin Marois29-Nov-22 15:30
professionalKevin Marois29-Nov-22 15:30 
AnswerRe: DropShadowEffect Above & Below Pin
Richard Deeming30-Nov-22 0:43
mveRichard Deeming30-Nov-22 0:43 
GeneralRe: DropShadowEffect Above & Below Pin
Kevin Marois30-Nov-22 6:32
professionalKevin Marois30-Nov-22 6:32 

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.