Root type of template Content

sarita54

Member
Joined
May 31, 2022
Messages
10
Programming Experience
Beginner
Hi ,
I don t find how to access root type of template content ?
Could you help me please?
Thanks
 
Are you asking about the ControlTemplate of a WPF control?

You'll need to provide more details about what you are trying to do. There is not much context in your original post.
 
In a listBox , I have a items defined in control template and i want to reach the border when I click on one of the button
XML:
  <ControlTemplate TargetType="ListBoxItem">
                        <Button x:Name="stack"  Click="Select_Country_Click" VerticalContentAlignment="Stretch"  HorizontalContentAlignment="Left" Background="Transparent" BorderThickness="0"  >
                            <Button.Style>
                                <Style TargetType="{x:Type Button}" x:Name="butt">
                                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate x:Name="mycontrol" TargetType="Button">
                                                <Border   Name="border" BorderThickness="2" VerticalAlignment="Stretch"  BorderBrush="Transparent" CornerRadius="3" Background="{TemplateBinding Background}">
                                                    <ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" />
                                                </Border>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsMouseOver" Value="True">
                                                        <Setter TargetName="border" Property="Background" Value="#14FFDC0C"  />
                                                        <Setter TargetName="border" Property="BorderBrush" Value="#FFDC0C" />
                                                    </Trigger>
                                                  
                                                    <Trigger Property="IsMouseOver" Value="True">
                                                        <Setter Property="Cursor" Value="Hand"  />
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </Button.Style>
                            <Grid  x:Name="gridList2" Height="70">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="20*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Image  x:Name="imagetemp2" Source="{Binding Flag}" Grid.Column="0" Height="70" Width="70" >
                                    <Image.Clip>
                                        <EllipseGeometry
                                          RadiusX="22"
                                          RadiusY="22"
                                          Center="35,35"/>
                                    </Image.Clip>
                                </Image>
                                <TextBlock x:Name="texttemp2" Tag="{Binding CountryShort}" Text="{Binding Title}" FontWeight="Regular" Margin="0,20,20,10" FontFamily="../Resources/Font/#SF Pro Text" Grid.Column="1"  FontSize="18" />
                            </Grid>
                        </Button>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter  Property="Background" Value="transparent"/>
                            </Trigger>
                            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                                <Setter Property="IsSelected" Value="True" />
                            </Trigger>
                          
                        </ControlTemplate.Triggers>
                        
                    </ControlTemplate>

For that I have tried :
Setter set= (Setter)((Button)sender).Style.Setters[1];
var value = set.Value;
TemplateContent mycontent= (((ControlTemplate)set.Value).Template);
after that I can see in debug that in the rootType of the template content I have the border (what I need ) , but I didn't find how access it
Could you help me please?
Thanks
 
What happens when your TargetType is a ListBox?
 
If it is the button that you put into the list box that you want to modify, then why are you asking about the list box? The button is not part of the default list box. It was something that you added.
 
If it is the button that you put into the list box that you want to modify, then why are you asking about the list box? The button is not part of the default list box. It was something that you added.
Yes sorry , i added it , do you know how access it please?
 
So are you saying that the setters for mouse over on lines 14-15 are not working? If they are working, there should be an equivalent event for mouse click.
 
Back
Top Bottom