![]()  | 
 
GENERAL: XAML Markup TextBlock.Style as attribute | 
 
    Post Reply  
   | 
  
| Author | |
   
   mnowaczy  
   
   Groupie  
   Joined: 16 June 2008 Status: Offline Points: 12  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Topic: GENERAL: XAML Markup TextBlock.Style as attributePosted: 16 June 2008 at 9:08am  | 
 
| 
   
    
   I have style defined im my Page resources like this: 
   
  <Style x:Key="Txt_1" TargetType="TextBlock"> <Setter Property="Padding" Value="0,5,0,5"/> </Style> then I use it for elements in stack panel and it works well: <StackPanel> <TextBlock Style="{StaticResource Txt_1}">sample 1</TextBlock> <TextBlock Style="{StaticResource Txt_1}">sample 2</TextBlock> </StackPanel> As long as I want all TextBlock inside StackPanel to be the same style I tried this: <StackPanel TextBlock.Style="{StaticResource Txt_1}"> <TextBlock>sample 1</TextBlock> <TextBlock>sample 2</TextBlock> </StackPanel> This approach works well with for example "FontWeight" property but not with "Style". I use your MarkupPad to test it.  | 
 |
![]()  | 
 |
   
   Oleg  
   
   Senior Member  
   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Posted: 17 June 2008 at 12:28am | 
 
| 
   
    
   Hi,
 
   
  Some properties in XAML are "Attached", some "Inherited". This can work for FontWeight - its Attached and Inherited property, but can't for Style property. 
Here valid XAML for your task: 
<Page xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> 
<StackPanel> <StackPanel.Resources> <Style TargetType="TextBlock"> <Setter Property="Padding" Value="0,5,0,5"/> </Style> </StackPanel.Resources> <TextBlock>sample 1</TextBlock> <TextBlock>sample 2</TextBlock> </StackPanel> </Page> 
    | 
 |
| 
   
     
     Oleg, Support Team 
   
  CODEJOCK SOFTWARE SOLUTIONS  | 
 |
![]()  | 
 |
   
   mnowaczy  
   
   Groupie  
   Joined: 16 June 2008 Status: Offline Points: 12  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Posted: 17 June 2008 at 5:27am | 
 
| 
   
    
   Thanks for explanation. 
   
  As far as this style is global for page I don't want to define it many times in different panels. I made such workaround :) <StackPanel> <StackPanel.Resources> <Style TargetType="TextBlock" BasedOn="{StaticResource Txt_1}"/> </StackPanel.Resources> <TextBlock>sample 1</TextBlock> <TextBlock>sample 2</TextBlock> </StackPanel>  | 
 |
![]()  | 
 |
   
   Oleg  
   
   Senior Member  
   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Posted: 17 June 2008 at 6:31am | 
 
| 
   
    
   yeap. also right :)
    
   
   | 
 |
| 
   
     
     Oleg, Support Team 
   
  CODEJOCK SOFTWARE SOLUTIONS  | 
 |
![]()  | 
 |
    Post Reply  
   | 
  |
|       
  
  Tweet   	
    | 
 
| Forum Jump | Forum Permissions  ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum  |