0

我有简单的 xaml 页面:

    <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>

按钮处理程序是这样看的:

        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);
    }

问题是,我只能运行这个方法大约 30 次。在我的实际应用中,最多尝试 2-4 次。

之后,应用程序在此行崩溃:

li.Style = style;

我的基于风格看起来像这样:

<Style TargetType="dxlc:LayoutItem" x:Name="DefaultLayoutItemStyle">
            <Setter Property="IsRequired" Value="{Binding IsRequired}"  />
            <Setter Property="Label" Value="{Binding Label}" />
        </Style>

问题在于 IsRequired 投标。Silverlight 无法获取该依赖项属性的 get_value。看起来 30 x XamlReader.Load 太多了......

你有任何提示如何解决这个问题吗?

我需要动态加载样式,因为用户可以修改它们。

我试图动态加载 MergedDictionaries 但结果是一样的。

非常感谢您。

汤姆

4

1 回答 1

0

我找到了。您需要为样式分配一个键并将其存储在资源中。之后我无法达到任何限制。

于 2013-11-20T14:22:47.713 回答