I have simple xaml page:
<Grid x:Name="LayoutRoot" dx:ThemeManager.ApplyApplicationTheme="True" Background="White" ShowGridLines="False" >
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="600" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<dxlc:LayoutControl Name="lc" Height="200" Width="400" Orientation="Vertical" />
<Button Content="Test" Click="button_Click" Grid.Row="1"/>
</Grid>
Button handler is looking this way:
private void button_Click(object sender, RoutedEventArgs e)
{
Style style;
LayoutItem li;
Sbo sbo;
string xamlStyle = @"<Style
TargetType=""dxlc:LayoutItem""
xmlns:x=""bla bla schemas.microsoft.com/winfx/2006/xaml""
xmlns=""bla bla schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:dxlc=""bla bla schemas.devexpress.com/winfx/2008/xaml/layoutcontrol""
>
</Style>";
this.lc.DeleteChildren();
this.lc.AvailableItems.Clear();
li = new LayoutItem();
style = XamlReader.Load(xamlStyle) as Style;
Style basedOnStyle = App.Current.Resources["DefaultLayoutItemStyle"] as Style;
style.BasedOn = basedOnStyle;
li.Style = style;
sbo = new Sbo() { IsRequired = true, Label = "any label" };
li.DataContext = sbo;
this.lc.Children.Add(li);
}
The problem is, that I can run this method only about 30 times. In my real application it is about 2-4 tries max.
After that the application is crashing on this line:
li.Style = style;
my based on style is looking like this:
<Style TargetType="dxlc:LayoutItem" x:Name="DefaultLayoutItemStyle">
<Setter Property="IsRequired" Value="{Binding IsRequired}" />
<Setter Property="Label" Value="{Binding Label}" />
</Style>
the problem is with IsRequired biding. Silverlight is unable to get_value of that dependency property. It is looking like 30 x XamlReader.Load is too much ...
Do you have any tip how to solve this?
I need to load styles dynamically because users can modify them.
I have tried to dynamically load MergedDictionaries but the result is the same.
Thank you VERY Much.
Tom