Click here to Skip to main content
15,914,419 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Style Not being Applied Pin
Kevin Marois25-Jul-17 4:36
professionalKevin Marois25-Jul-17 4:36 
QuestionHandle DataGrid Row Model Property Change Pin
Kevin Marois21-Jun-17 12:45
professionalKevin Marois21-Jun-17 12:45 
AnswerRe: Handle DataGrid Row Model Property Change Pin
Mycroft Holmes21-Jun-17 20:54
professionalMycroft Holmes21-Jun-17 20:54 
AnswerRe: Handle DataGrid Row Model Property Change Pin
Pete O'Hanlon21-Jun-17 21:46
mvePete O'Hanlon21-Jun-17 21:46 
GeneralRe: Handle DataGrid Row Model Property Change Pin
Kevin Marois22-Jun-17 4:01
professionalKevin Marois22-Jun-17 4:01 
GeneralRe: Handle DataGrid Row Model Property Change Pin
Pete O'Hanlon22-Jun-17 5:03
mvePete O'Hanlon22-Jun-17 5:03 
GeneralRe: Handle DataGrid Row Model Property Change Pin
Mycroft Holmes22-Jun-17 14:41
professionalMycroft Holmes22-Jun-17 14:41 
GeneralRe: Handle DataGrid Row Model Property Change Pin
Pete O'Hanlon22-Jun-17 21:18
mvePete O'Hanlon22-Jun-17 21:18 
GeneralStop user from killing of a running wpf application from background processes in task manager. Pin
Naushad Ansari15-Jun-17 23:24
Naushad Ansari15-Jun-17 23:24 
GeneralRe: Stop user from killing of a running wpf application from background processes in task manager. Pin
Pete O'Hanlon15-Jun-17 23:46
mvePete O'Hanlon15-Jun-17 23:46 
QuestionBind To DP On Control Pin
Kevin Marois15-Jun-17 5:26
professionalKevin Marois15-Jun-17 5:26 
AnswerRe: Bind To DP On Control Pin
Pete O'Hanlon15-Jun-17 6:35
mvePete O'Hanlon15-Jun-17 6:35 
GeneralRe: Bind To DP On Control Pin
Kevin Marois15-Jun-17 6:39
professionalKevin Marois15-Jun-17 6:39 
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
BenScharbach12-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
mvePete 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
eddieangel15-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:

XML
<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:

XML
<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 

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.