Click here to Skip to main content
15,886,788 members
Home / Discussions / WPF
   

WPF

 
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 
QuestionNavigationControl - Continued Pin
Kevin Marois2-May-23 14:49
professionalKevin Marois2-May-23 14:49 
AnswerRe: NavigationControl - Continued Pin
Richard Deeming2-May-23 22:19
mveRichard Deeming2-May-23 22:19 
GeneralRe: NavigationControl - Continued Pin
Kevin Marois3-May-23 5:21
professionalKevin Marois3-May-23 5:21 
GeneralRe: NavigationControl - Continued Pin
Kevin Marois3-May-23 15:10
professionalKevin Marois3-May-23 15:10 
GeneralRe: NavigationControl - Continued Pin
Richard Deeming3-May-23 21:35
mveRichard Deeming3-May-23 21:35 
QuestionWPF 3D rendering Pin
Kenneth Haugland1-May-23 4:52
mvaKenneth Haugland1-May-23 4:52 
AnswerRe: WPF 3D rendering Pin
Gerry Schmitz2-May-23 6:14
mveGerry Schmitz2-May-23 6:14 
GeneralRe: WPF 3D rendering Pin
Kenneth Haugland2-May-23 9:59
mvaKenneth Haugland2-May-23 9:59 
AnswerRe: WPF 3D rendering Pin
RedDk2-May-23 8:03
RedDk2-May-23 8:03 
GeneralRe: WPF 3D rendering Pin
Kenneth Haugland2-May-23 10:01
mvaKenneth Haugland2-May-23 10:01 
QuestionExpander in ListBoxItem Width Problem Pin
Kevin Marois27-Apr-23 7:19
professionalKevin Marois27-Apr-23 7:19 
AnswerRe: Expander in ListBoxItem Width Problem Pin
Richard Deeming1-May-23 23:09
mveRichard Deeming1-May-23 23:09 
GeneralRe: Expander in ListBoxItem Width Problem Pin
Kevin Marois2-May-23 7:12
professionalKevin Marois2-May-23 7:12 
QuestionSpinning Indicator Control Error Pin
Kevin Marois26-Apr-23 14:32
professionalKevin Marois26-Apr-23 14:32 
AnswerRe: Spinning Indicator Control Error Pin
Gerry Schmitz27-Apr-23 7:01
mveGerry Schmitz27-Apr-23 7:01 
GeneralRe: Spinning Indicator Control Error Pin
Kevin Marois27-Apr-23 7:27
professionalKevin Marois27-Apr-23 7:27 

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.