本文介绍了C#等同于XAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人给我以下代码的C#等效物

please anybody give me the C# equivalent of the below code

<dg:DataGridTextColumn.ElementStyle>
                       <Style TargetType="TextBlock">
                           <Setter Property="TextAlignment" Value="Center" />
                       </Style>
                   </dg:DataGridTextColumn.ElementStyle>




在此先感谢




thanks in advance

推荐答案

Style style = new System.Windows.Style();
style.TargetType = typeof(TextBlock);

Setter setter = new Setter();
setter.Property = DependencyProperty.Register("TextAlignment", typeof(TextAlignment), typeof(Setter));
setter.Value = TextAlignment.Center;
style.Setters.Add(setter);
DataGridTextColumn dg = new DataGridTextColumn();
dg.ElementStyle = style;



我认为这会有所帮助.



I think this can help.


这篇关于C#等同于XAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:58