Click here to Skip to main content
15,904,155 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: NavigationControl - Part 3 Pin
Kevin Marois15-May-23 17:14
professionalKevin Marois15-May-23 17:14 
QuestionBubbling Event Question Pin
Kevin Marois9-May-23 14:32
professionalKevin Marois9-May-23 14:32 
AnswerRe: Bubbling Event Question Pin
Gerry Schmitz12-May-23 5:28
mveGerry Schmitz12-May-23 5:28 
GeneralRe: Bubbling Event Question Pin
Kevin Marois12-May-23 5:35
professionalKevin Marois12-May-23 5:35 
GeneralRe: Bubbling Event Question Pin
Gerry Schmitz12-May-23 5:46
mveGerry Schmitz12-May-23 5:46 
GeneralRe: Bubbling Event Question Pin
Kevin Marois12-May-23 6:16
professionalKevin Marois12-May-23 6:16 
AnswerRe: Bubbling Event Question Pin
Kenneth Haugland14-May-23 9:55
mvaKenneth Haugland14-May-23 9:55 
GeneralRe: Bubbling Event Question Pin
Kevin Marois14-May-23 10:40
professionalKevin Marois14-May-23 10:40 
GeneralRe: Bubbling Event Question Pin
Kenneth Haugland14-May-23 11:06
mvaKenneth Haugland14-May-23 11:06 
GeneralRe: Bubbling Event Question Pin
Kevin Marois14-May-23 11:08
professionalKevin Marois14-May-23 11:08 
GeneralRe: Bubbling Event Question Pin
Kenneth Haugland14-May-23 11:19
mvaKenneth Haugland14-May-23 11:19 
GeneralRe: Bubbling Event Question Pin
Kevin Marois15-May-23 17:47
professionalKevin Marois15-May-23 17:47 
GeneralRe: Bubbling Event Question Pin
Kenneth Haugland15-May-23 18:46
mvaKenneth Haugland15-May-23 18:46 
GeneralRe: Bubbling Event Question Pin
Kevin Marois16-May-23 7:02
professionalKevin Marois16-May-23 7:02 
QuestionExpander Header Content Stretch Pin
Kevin Marois9-May-23 11:25
professionalKevin Marois9-May-23 11:25 
AnswerRe: Expander Header Content Stretch Pin
Richard Deeming9-May-23 21:48
mveRichard Deeming9-May-23 21:48 
GeneralRe: Expander Header Content Stretch Pin
Kevin Marois13-May-23 6:05
professionalKevin Marois13-May-23 6:05 
QuestionVB.NET WPF drag and drop for LISTBOX and TREEVIEWs..Anyone help with examples? Pin
Member 84579549-May-23 8:51
Member 84579549-May-23 8:51 
AnswerRe: VB.NET WPF drag and drop for LISTBOX and TREEVIEWs..Anyone help with examples? Pin
Richard MacCutchan9-May-23 10:14
mveRichard MacCutchan9-May-23 10:14 
AnswerRe: VB.NET WPF drag and drop for LISTBOX and TREEVIEWs..Anyone help with examples? Pin
Richard Deeming9-May-23 21:38
mveRichard Deeming9-May-23 21:38 
QuestionListBoxItem DataTemplate with HyperLink Problem Pin
Kevin Marois8-May-23 11:52
professionalKevin Marois8-May-23 11:52 
AnswerRe: ListBoxItem DataTemplate with HyperLink Problem Pin
Richard Deeming8-May-23 21:44
mveRichard Deeming8-May-23 21:44 
GeneralRe: ListBoxItem DataTemplate with HyperLink Problem Pin
Kevin Marois9-May-23 5:29
professionalKevin Marois9-May-23 5:29 
QuestionCustomControl Styling Question Pin
Kevin Marois4-May-23 17:22
professionalKevin Marois4-May-23 17:22 
I created this dummy control to ask the question... It's a TextBox with 2 buttons.

If I wanted to give this control in an assembly to another developer, how would they modify the style to fit their needs? You can see I have named my brushes with some care, but what about changing triggers or maybe animations and other things? If this is all inside an assembly, how does the developer know how the style works what the style does?

Generica.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:MyControl">

    <SolidColorBrush x:Key="Button.Normal.Foreground" Color="SteelBlue"/>
    <SolidColorBrush x:Key="Button.Normal.Background" Color="BlanchedAlmond"/>
    <SolidColorBrush x:Key="Button.Normal.Border" Color="DarkGray"/>
    <SolidColorBrush x:Key="Button.Hover.Background" Color="Orange"/>
    <SolidColorBrush x:Key="Button.Hover.Border" Color="#FF3C7FB1"/>
    <SolidColorBrush x:Key="Button.Pressed.Foreground" Color="Salmon"/>
    <SolidColorBrush x:Key="Button.Pressed.Background" Color="#FF737B7F"/>
    <SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/>
    <SolidColorBrush x:Key="Button.Disabled.Foreground" Color="DarkGray"/>
    <SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>

    <SolidColorBrush x:Key="TextBlock.Normal.Foreground" Color="SteelBlue"/>
    <SolidColorBrush x:Key="TextBlock.Normal.Background" Color="BlanchedAlmond"/>
    <SolidColorBrush x:Key="TextBlock.Normal.Border" Color="DarkGray"/>
    <SolidColorBrush x:Key="TextBlock.Hover.Background" Color="#FFBEE6FD"/>
    <SolidColorBrush x:Key="TextBlock.Hover.Foreground" Color="Blue"/>
    <SolidColorBrush x:Key="TextBlock.Hover.Border" Color="#FF3C7FB1"/>
    <SolidColorBrush x:Key="TextBlock.Pressed.Foreground" Color="Blue"/>
    <SolidColorBrush x:Key="TextBlock.Pressed.Background" Color="#FF737B7F"/>
    <SolidColorBrush x:Key="TextBlock.Pressed.Border" Color="#FF2C628B"/>
    <SolidColorBrush x:Key="TextBlock.Disabled.Foreground" Color="DarkGray"/>
    <SolidColorBrush x:Key="TextBlock.Disabled.Background" Color="#FFF4F4F4"/>

    <SolidColorBrush x:Key="TextBox.Normal.Foreground" Color="SteelBlue"/>
    <SolidColorBrush x:Key="TextBox.Normal.Background" Color="White"/>
    <SolidColorBrush x:Key="TextBox.Normal.Border" Color="DarkGray"/>
    <SolidColorBrush x:Key="TextBox.Hover.Background" Color="#FFBEE6FD"/>
    <SolidColorBrush x:Key="TextBox.Hover.Border" Color="#FF3C7FB1"/>
    <SolidColorBrush x:Key="TextBox.Pressed.Background" Color="#FF737B7F"/>
    <SolidColorBrush x:Key="TextBox.Pressed.Border" Color="#FF2C628B"/>
    <SolidColorBrush x:Key="TextBox.Disabled.Foreground" Color="DarkGray"/>
    <SolidColorBrush x:Key="TextBox.Disabled.Background" Color="#FFF4F4F4"/>

    <Geometry x:Key="addButtonPathData">
        M20 14H14V20H10V14H4V10H10V4H14V10H20V14Z
    </Geometry>

    <Geometry x:Key="removeButtonPathData">
        M20 14H4V10H20V14Z
    </Geometry>

    <Style x:Key="pathImageButtonStyle" 
           TargetType="{x:Type local:PathImageButton}">

        <Setter Property="Background" Value="{StaticResource Button.Normal.Background}"/>
        <Setter Property="Height" Value="35"/>
        <Setter Property="Width" Value="75"/>

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type local:PathImageButton}">

                    <Grid x:Name="Grid">

                        <Border x:Name="border"
                                Margin="2" 
                                Background="{StaticResource Button.Normal.Background}" 
                                BorderBrush="DarkGray" 
                                BorderThickness="1" 
                                CornerRadius="5">

                            <Grid>

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>

                                <Path Grid.Column="0" 
                                      x:Name="path"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center"
                                      Data="{Binding PathData, RelativeSource={RelativeSource TemplatedParent}}"
                                      Fill="{StaticResource Button.Normal.Foreground}"
                                      Stretch="Uniform"
                                      Margin="4"/>

                                <TextBlock Grid.Column="1" 
                                           x:Name="caption" 
                                           Text="{Binding Caption, RelativeSource={RelativeSource TemplatedParent}}"
                                           Foreground="{StaticResource TextBlock.Normal.Foreground}"
                                           Background="{StaticResource TextBlock.Normal.Background}"
                                           HorizontalAlignment="Left"
                                           VerticalAlignment="Center"
                                           Margin="0,2,2,2"/>

                            </Grid>

                        </Border>

                    </Grid>

                    <ControlTemplate.Triggers>

                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="path" Property="Fill" Value="{StaticResource Button.Normal.Foreground}" />
                            <Setter TargetName="caption" Property="Foreground" Value="{StaticResource TextBlock.Hover.Foreground}" />
                            <Setter TargetName="border" Property="Background" Value="{StaticResource Button.Hover.Background}" />
                            <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Hover.Border}" />
                            <Setter TargetName="border" Property="BorderThickness" Value="1" />
                        </Trigger>

                        <Trigger Property="IsPressed" Value="true">
                            <Setter TargetName="path" Property="Fill" Value="{StaticResource Button.Pressed.Foreground}" />
                            <Setter TargetName="caption" Property="Foreground" Value="{StaticResource TextBlock.Pressed.Foreground}" />
                            <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Pressed.Foreground}" />
                            <Setter TargetName="border" Property="BorderThickness" Value="1" />
                        </Trigger>

                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="path" Property="Fill" Value="{StaticResource Button.Disabled.Foreground}" />
                            <Setter TargetName="caption" Property="Foreground" Value="{StaticResource TextBlock.Disabled.Foreground}" />
                            <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Disabled.Foreground}" />
                            <Setter TargetName="border" Property="BorderThickness" Value="0" />
                        </Trigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

    <Style x:Key="buttonBaseStyle" 
           BasedOn="{StaticResource pathImageButtonStyle }"
           TargetType="{x:Type local:PathImageButton}">

        <Setter Property="Height" Value="32"/>
        <Setter Property="Width" Value="100"/>

    </Style>

    <Style x:Key="addButtonStyle" 
           BasedOn="{StaticResource buttonBaseStyle }"
           TargetType="{x:Type local:PathImageButton}">

        <Setter Property="Caption" Value="Add"/>
        <Setter Property="PathData" Value="{StaticResource addButtonPathData}"/>

    </Style>

    <Style x:Key="removeButtonStyle" 
           BasedOn="{StaticResource buttonBaseStyle }"
           TargetType="{x:Type local:PathImageButton}">

        <Setter Property="Caption" Value="Remove"/>
        <Setter Property="PathData" Value="{StaticResource removeButtonPathData}"/>

    </Style>

    <Style TargetType="{x:Type local:CustomControl1}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CustomControl1}">

                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Width="{Binding Width, RelativeSource={RelativeSource TemplatedParent}}">

                        <Grid>

                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height=""/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width=""/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Row="0" 
                                        Grid.Column="0"
                                        Orientation="Horizontal"
                                        HorizontalAlignment="Stretch">

                                <TextBox Background="{StaticResource TextBox.Normal.Background}"
                                         FontSize="18"
                                         VerticalContentAlignment="Center"
                                         Width="250"
                                         Margin="2"/>

                                <local:PathImageButton Style="{StaticResource addButtonStyle}"/>

                                <local:PathImageButton Style="{StaticResource removeButtonStyle}"
                                                       IsEnabled="True"/>

                            </StackPanel>

                        </Grid>

                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

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

AnswerRe: CustomControl Styling Question Pin
Pete O'Hanlon4-May-23 20:29
mvePete O'Hanlon4-May-23 20:29 

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.