Click here to Skip to main content
15,888,521 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF Custom Control & User Control Pin
Kevin Marois31-Dec-22 14:59
professionalKevin Marois31-Dec-22 14:59 
AnswerRe: WPF Custom Control & User Control Pin
Gerry Schmitz31-Dec-22 10:58
mveGerry Schmitz31-Dec-22 10:58 
GeneralRe: WPF Custom Control & User Control Pin
Kevin Marois31-Dec-22 14:59
professionalKevin Marois31-Dec-22 14:59 
GeneralRe: WPF Custom Control & User Control Pin
Gerry Schmitz1-Jan-23 2:59
mveGerry Schmitz1-Jan-23 2:59 
GeneralRe: WPF Custom Control & User Control Pin
Kevin Marois1-Jan-23 14:27
professionalKevin Marois1-Jan-23 14:27 
QuestionPath Image Pin
Kevin Marois28-Dec-22 16:27
professionalKevin Marois28-Dec-22 16:27 
AnswerRe: Path Image Pin
Gerry Schmitz28-Dec-22 17:02
mveGerry Schmitz28-Dec-22 17:02 
GeneralRe: Path Image Pin
Kevin Marois28-Dec-22 18:53
professionalKevin Marois28-Dec-22 18:53 
GeneralRe: Path Image Pin
Gerry Schmitz29-Dec-22 4:40
mveGerry Schmitz29-Dec-22 4:40 
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 
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.

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.