This is a migrated thread and some comments may be shown as answers.

How to add template with button

2 Answers 73 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
HDC
Top achievements
Rank 1
HDC asked on 08 Aug 2011, 06:51 PM

I want to add a "FileOpen" editor to the propertygrid.

My datatemplate contains a textbox and a radbutton, i want to be able to hook the buttonclick event so i can popup a filedialog. I can create the template and put it in the propertygrid. 

<Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="TextBox">
          <Grid x:Name="RootElement">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="20" />
            </Grid.ColumnDefinitions>
 
            <Border x:Name="Border"
                                    Grid.ColumnSpan="3"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="{StaticResource ControlOuterBorder_CornerRadius}"
                                    Opacity="1" />
            <Border x:Name="ReadOnlyVisualElement"
                                    Grid.ColumnSpan="3"
                                    Background="{StaticResource ControlBackground_ReadOnly}"
                                    CornerRadius="{StaticResource ControlOuterBorder_CornerRadius}"
                                    Opacity="0" />
 
            <Border x:Name="DisabledVisualElement"
                                    Grid.ColumnSpan="3"
                                    Background="{StaticResource ControlBackground_Disabled}"
                                    BorderBrush="{StaticResource ControlOuterBorder_Disabled}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="{StaticResource ControlOuterBorder_CornerRadius}"
                                    IsHitTestVisible="False"
                                    Opacity="0" />
            <ScrollViewer x:Name="ContentElement"
                                          Grid.ColumnSpan="2"
                                          BorderThickness="0"
                                          IsTabStop="False"
                                          Padding="{TemplateBinding Padding}" />
            <Border x:Name="FocusVisualElement"
                                    Grid.ColumnSpan="3"
                                    BorderBrush="{StaticResource ControlOuterBorder_Focused}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="{StaticResource ControlOuterBorder_CornerRadius}"
                                    IsHitTestVisible="False"
                                    Opacity="0" />
            <!--  SearchButton  -->
            <telerik:RadButton Grid.Column="2"
                                               Margin="5 3"
                                               HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                               VerticalAlignment="{TemplateBinding VerticalContentAlignment}"                                              
                                               Style="{StaticResource SearchButton}" />
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

My datatemplate will then be:

<DataTemplate x:Key="SearchFileTextBox">
    <TextBox Text="{Binding Path, Mode=TwoWay}" Style="{StaticResource SearchTextBoxStyle}" />
  </DataTemplate>

I can not figure out how i can hook the click event on the button.

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Ivanov
Telerik team
answered on 09 Aug 2011, 09:02 AM
Hello Peter,

You may place the RadButton in the DataTemplate and subscribe to the event there. I couldn't quite understand why are you using a ControlTemplate. Would you please shed some more light on this. However, I have prepared a simple demo project. I am attaching it for your reference.

All the best,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
HDC
Top achievements
Rank 1
answered on 09 Aug 2011, 11:02 AM
I am using a control template because i wanted to show a good looking text editor with an integrated button.

But this will do the trick too!

Thanks a lot for your help.

Best Regards,

Peter

Tags
PropertyGrid
Asked by
HDC
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
HDC
Top achievements
Rank 1
Share this question
or