Friday, March 6, 2015

Loading Resources From Assembly and Assign to An Element Programatically

Suppose that you have resource in your assembly:

 <Style x:Key="TextBlock_left" TargetType="{x:Type TextBlock}">  
   <Setter Property="HorizontalAlignment" Value="Left" />  
   <Setter Property="VerticalAlignment" Value="Center" />  
   <Setter Property="Margin" Value="5" />  
   <Setter Property="TextWrapping" Value="Wrap" />  
 </Style>  

And then you want to assign this style to an element:
DataGridTextColumn.ElementStyle = (Style)FindResource("TextBlock_right");

That's it!
Post a Comment