开发者

How to set the style programmatically

I have the following style but i need to make it programmatically:

<xcdg:DataGridControl MinHeight="300" 
                      Name="listViewUnallocated" 
                      ItemsSource="{Binding Source={StaticResource
                                         cvs_unallocatedTerminals}}"
                      AllowDrop="True" 
                      D开发者_如何学Gorop="Grid_Drop" 
                      MouseMove="Grid_MouseMove" 
                      KeyUp="listViewUnallocated_KeyUp"
                      MouseDoubleClick="gridUnallocated_MouseDoubleClick"
                      ReadOnly="True"
                      DockPanel.Dock="Top">
    <xcdg:DataGridControl.Resources>
        <Style TargetType="{x:Type xcdg:DataRow}" x:Name="selectedStyleTrigger">
            <Style.Triggers>
                <DataTrigger Binding="{Binding TerminalId}" Value="72948028">
                    <Setter Property="Background" Value="Red" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </xcdg:DataGridControl.Resources>


In the code-behind file of the control, try:

this.Style = Resources["ResourceName"] as Style;


Set x:Key in XAML & in code-behind use:

something.Style = (Style) FindResource("YourResourceKey");


Hi we can set style programmatically like this.

Style rowStyle = new Style(typeof(DataGridRow));

DataTrigger dataTrigger = new DataTrigger("TerminalId");
Binding binding = new Binding();
dataTrigger.Binding = binding;
dataTrigger.Value = 72948028;

Setter setter = new Setter(DataGridRow.BackgroundProperty, Brushes.Red);

dataTrigger.Setters.Add(setter);

rowStyle.Triggers.Add(dataTrigger);
listViewUnallocated.RowStyle = rowStyle;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜