Click here to Skip to main content
14,547,127 members

Silverlight / WPF

 
GeneralRe: Bind To DP On Control Pin
Richard Deeming15-Jun-17 6:58
mveRichard Deeming15-Jun-17 6:58 
GeneralRe: Bind To DP On Control Pin
Kevin Marois15-Jun-17 7:03
professionalKevin Marois15-Jun-17 7:03 
AnswerRe: Bind To DP On Control Pin
BenScharbach12-Aug-17 9:06
MemberBenScharbach12-Aug-17 9:06 
QuestionCommand Binding In User Control Pin
Kevin Marois9-Jun-17 12:24
professionalKevin Marois9-Jun-17 12:24 
AnswerRe: Command Binding In User Control Pin
Pete O'Hanlon9-Jun-17 21:26
subeditorPete O'Hanlon9-Jun-17 21:26 
GeneralRe: Command Binding In User Control Pin
Kevin Marois12-Jun-17 5:01
professionalKevin Marois12-Jun-17 5:01 
QuestionStyle User Control Pin
Kevin Marois22-May-17 5:19
professionalKevin Marois22-May-17 5:19 
AnswerRe: Style User Control Pin
eddieangel15-Sep-17 10:28
Membereddieangel15-Sep-17 10:28 
In this WPF can be a real pain. I wanted to create a textbox that had a browse button inside of it to match some other controls and it was quite the hassle. Basically, the flow is this:

1. Create your user control, hopefully it is based off of other controls so you can use the existing dependency properties
2. In your resources.xaml file, add a reference to the xmlns of your control
3. Add style in resources.xaml

For me, my control is called a BrowseTextBox. The style looks like this:

<Style x:Key="{x:Type cont:BrowseTextBox}"

           TargetType="{x:Type cont:BrowseTextBox}"

           BasedOn="{StaticResource {x:Type TextBox}}">
        <Setter Property="BorderThickness"

                Value="1" />
        <Setter Property="Background"

                Value="#FFFFFF" />
        <Setter Property="Foreground"

                Value="#000000" />
        <Setter Property="Padding"

                Value="5,3" />
        <Setter Property="VerticalContentAlignment"

                Value="Center" />
        <Setter Property="HorizontalContentAlignment"

                Value="Stretch" />
        <Setter Property="FocusVisualStyle"

                Value="{x:Null}" />
        <Setter Property="SnapsToDevicePixels"

                Value="True" />
        <Setter Property="KeyboardNavigation.TabNavigation"

                Value="Once" />
        <Setter Property="KeyboardNavigation.ControlTabNavigation"

                Value="Cycle" />
        <Setter Property="IsTabStop"

                Value="False" />
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate />
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type cont:BrowseTextBox}">
                    <Grid x:Name="LayoutGrid">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="TextColumn"

                                              Width="*" />
                            <ColumnDefinition x:Name="ButtonsColumn"

                                              Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0"

                                                         To="1"

                                                         Storyboard.TargetProperty="Opacity"

                                                         Storyboard.TargetName="MouseOverVisual" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"

                                                                       Storyboard.TargetName="Focus">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="Background"

                                BorderBrush="{TemplateBinding BorderBrush}"

                                BorderThickness="1"

                                Background="{TemplateBinding Background}"

                                Grid.ColumnSpan="2" />
                        <Border x:Name="MouseOverVisual"

                                BorderThickness="1"

                                BorderBrush="{StaticResource TextBoxFocus}"

                                Background="{TemplateBinding Background}"

                                Grid.ColumnSpan="2"

                                Opacity="0" />
                        <Border x:Name="Focus"

                                BorderBrush="{StaticResource TextBoxFocus}"

                                BorderThickness="{TemplateBinding BorderThickness}"

                                Grid.ColumnSpan="2"

                                IsHitTestVisible="False"

                                Visibility="Collapsed" />
                        <Border x:Name="ReadOnly"

                                BorderBrush="{TemplateBinding BorderBrush}"

                                BorderThickness="1"

                                Background="#FF575859"

                                Grid.ColumnSpan="2">
                            <Border.Visibility>
                                <Binding Path="IsReadOnly"

                                         RelativeSource="{RelativeSource TemplatedParent}">
                                    <Binding.Converter>
                                        <telerik:BooleanToVisibilityConverter />
                                    </Binding.Converter>
                                </Binding>
                            </Border.Visibility>
                        </Border>
                        <ScrollViewer x:Name="PART_ContentHost"

                                      Grid.Column="0"

                                      BorderBrush="Transparent" />
                        <Border x:Name="PART_SearchIconBorder"

                                Grid.Column="1"

                                BorderThickness="0"

                                VerticalAlignment="Stretch"

                                HorizontalAlignment="Stretch">
                            <telerik:RadButton x:Name="Search"

                                               Style="{StaticResource TextButton}"

                                               Content="..."

                                               ToolTip="Browse"

                                               VerticalAlignment="Stretch"

                                               Width="15" />
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


Mine is using some Telerik styles as that is what I am using on the rest of my form. The control in the view looks like this:

<cont:BrowseTextBox x:Name="CurrentObservation_FilePath"

                                                Grid.Row="7"

                                                Grid.Column="1"

                                                HorizontalAlignment="Stretch"

                                                Margin="2,2,0,0"

                                                Browse="FileBrowser_OnClick" />


The user control is pretty much just the same thing you are talking about, an existing type of control (text box) with another control (button) inside of it.
QuestionBind ColumnGroup text Pin
Mycroft Holmes18-May-17 16:01
professionalMycroft Holmes18-May-17 16:01 
AnswerRe: Bind ColumnGroup text (Resolved) Pin
Mycroft Holmes23-May-17 22:47
professionalMycroft Holmes23-May-17 22:47 
QuestionCustom SplitButton Control Styling Pin
Kevin Marois18-May-17 10:24
professionalKevin Marois18-May-17 10:24 
QuestionRe: Custom SplitButton Control Styling Pin
Gerry Schmitz18-May-17 11:34
mveGerry Schmitz18-May-17 11:34 
AnswerRe: Custom SplitButton Control Styling Pin
Kevin Marois18-May-17 12:37
professionalKevin Marois18-May-17 12:37 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz18-May-17 12:55
mveGerry Schmitz18-May-17 12:55 
GeneralRe: Custom SplitButton Control Styling Pin
Kevin Marois18-May-17 19:03
professionalKevin Marois18-May-17 19:03 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz18-May-17 19:37
mveGerry Schmitz18-May-17 19:37 
GeneralRe: Custom SplitButton Control Styling Pin
Kevin Marois19-May-17 5:04
professionalKevin Marois19-May-17 5:04 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz19-May-17 5:33
mveGerry Schmitz19-May-17 5:33 
GeneralRe: Custom SplitButton Control Styling Pin
Kevin Marois22-May-17 5:23
professionalKevin Marois22-May-17 5:23 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz22-May-17 6:15
mveGerry Schmitz22-May-17 6:15 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz22-May-17 6:35
mveGerry Schmitz22-May-17 6:35 
GeneralRe: Custom SplitButton Control Styling Pin
Kevin Marois22-May-17 6:50
professionalKevin Marois22-May-17 6:50 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz22-May-17 7:07
mveGerry Schmitz22-May-17 7:07 
QuestionTheming Question Pin
Kevin Marois5-May-17 7:29
professionalKevin Marois5-May-17 7:29 
QuestionWPF MVVM ListView Bound to ObservableCollection doesnt update after i make changes Pin
Member 1288059527-Apr-17 7:25
MemberMember 1288059527-Apr-17 7:25 

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.