0

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

Tom
  • 23
  • 7
  • I have tried this with simple checkbox and stackpanel. The result is: style can be assigned only 31 times. The 32. attempt generates an exception. IsChecked binding is throwing an exception. – Tom Nov 20 '13 at 12:49

1 Answers1

0

I have found it. You need to assign style a key and store it in resources. After that I can not reach any limit.

Tom
  • 23
  • 7