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 に答える