Reputation: 4692
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"
Drop="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>
Upvotes: 57
Views: 71216
Reputation: 5841
Set x:Key
in XAML & in code-behind use:
something.Style = (Style) FindResource("YourResourceKey");
Upvotes: 55
Reputation: 281
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;
Upvotes: 21
Reputation: 45083
In the code-behind file of the control, try:
this.Style = Resources["ResourceName"] as Style;
Upvotes: 67