How to add template with button

3 posts, 1 answers
  1. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 08 Aug 2011 Link to this post

    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. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 09 Aug 2011 Link to this post

    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 >>
  3. DevCraft banner
  4. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 09 Aug 2011 Link to this post

    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

Back to Top