Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

ItemContainerStyle and ItemTemplate change template controls properties

$
0
0

Hello

I have a ListBox using the next ItemTemplate:

 

<

DataTemplatex:Key="MenuItemTemplate">

     <

StackPanelMargin="0,5,0,0"Width="100">

          <

ImageWidth="48"Source="Images\gears.png"Height="48"/>

          <

TextBlockBackground="{x:Null}"FontSize="12"FontWeight="Normal"Text="{Binding Mode=OneWay, XPath=Title}"TextWrapping="Wrap"d:LayoutOverrides="Width"HorizontalAlignment="Center"x:Name="tbText"/>

     </

StackPanel>

</

DataTemplate>

 

Now I also run over the ItemContainerStyle  to remove the blue rectangle when item selection occur, I also removed the default white Foreground, instead I added a blue border, until here no problems:

 

<

Stylex:Key="MenuItemsContainerStyle"TargetType="{x:Type ListBoxItem}">

     <

SetterProperty="Background"Value="Transparent"/>

     <

SetterProperty="Template">

     <

Setter.Value>

          <

ControlTemplateTargetType="{x:Type ListBoxItem}">

               <

BorderSnapsToDevicePixels="true"x:Name="Bd"Background="{TemplateBinding Background}"BorderBrush="{TemplateBinding BorderBrush}"BorderThickness="{TemplateBinding BorderThickness}"Padding="{TemplateBinding Padding}">

                    <

ContentPresenterSnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

               </

Border>

               <

ControlTemplate.Triggers>

                    <

TriggerProperty="IsSelected"Value="true">

                         <

SetterProperty="BorderBrush"TargetName="Bd"Value="{DynamicResource {xTongue Tiedtatic SystemColors.HighlightBrushKey}}"/>

                         <

SetterProperty="BorderThickness"TargetName="Bd"Value="1" />

                    </

Trigger>

                    <

TriggerProperty="IsEnabled"Value="false">

                         <

SetterProperty="Foreground"Value="{DynamicResource {xTongue Tiedtatic SystemColors.GrayTextBrushKey}}"/>

                    </

Trigger>

               </

ControlTemplate.Triggers>

          </

ControlTemplate>

     </

Setter.Value>

</

Setter>

</

Style>

 

 

Now the thing is I want to set the TextBlock font weight Bold!!!

How can I achieve that, how can I chenge properties of a control inside my template when the ListBoxItem is selected?

 

The next line does not work so please do not give me that solution:

                         <SetterProperty="FontWeight"Value="Bold"/>

 

Thanx

Itzik

 

P.S

I also want to change the ImageSource but I assume it will be done the same


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>