在 Framework 3.5 中使用 VisualStateManager 时出现 Locbaml 错误

发布于 2024-09-19 08:43:17 字数 5059 浏览 9 评论 0原文

当我翻译 Tester.WPF.resources.dll 时,出现错误。就像baml文件将VisualStateGroup修改为集合一样。我不明白。该项目在默认语言下启动时没有任何问题,但如果我更改文化,它就会崩溃。我重建它,仍然是这个错误,即使是从头开始。通过这个小测试项目,仍然得到相同的错误:

Object of type 'System.Windows.VisualStateGroup' cannot be converted to type 'System.Collections.ObjectModel.Collection`1[System.Windows.VisualStateGroup]'.

StackTrace

    at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)   at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.SetClrComplexProperty(Object parentObject, MemberInfo memberInfo, Object o)
   at System.Windows.Markup.BamlRecordReader.SetPropertyValueToParent(Boolean fromStartTag, Boolean& isMarkupExtension)
   at System.Windows.Markup.BamlRecordReader.ReadElementEndRecord(Boolean fromNestedBamlRecordReader)
   at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
   at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
   at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
   at System.Windows.Markup.TreeBuilder.Parse()
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at Tester.WPF.Window1.InitializeComponent()

TestWindow

<Window x:Class="Arofex.Translator.Tester.WPF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
     xmlns:Controlsw="clr-namespace:System.Windows;assembly=WPFToolkit"
    >
<Grid>
    <Border x:Name="LayoutRoot"  BorderThickness="1" BorderBrush="Red" RenderTransformOrigin="0.5,0.5" Width="500" CornerRadius="5" Margin="0,0,0,30">
        <Border.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </Border.RenderTransform>
        <Controlsw:VisualStateManager.VisualStateGroups>
            <Controlsw:VisualStateGroup x:Name="VSGVisiblbe">
                <Controlsw:VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="00:00:00.2000000"/>
                </Controlsw:VisualStateGroup.Transitions>
                <Controlsw:VisualState x:Name="StateNormal"/>
                <Controlsw:VisualState x:Name="StateStart">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.034"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-57"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </Controlsw:VisualState>
            </Controlsw:VisualStateGroup>
        </Controlsw:VisualStateManager.VisualStateGroups>
        <StackPanel Orientation="Vertical" Background="LightGray">
            <TextBlock Text="My text to test translation" />

        </StackPanel>
    </Border>

应用程序代码

 private void Application_Startup(object sender, StartupEventArgs e)
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-BE");
        Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-BE");
        var dictionaryList = new List<Uri>();
        foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
            dictionaryList.Add(dictionary.Source);
        Application.Current.Resources.MergedDictionaries.Clear();
        foreach (Uri uri in dictionaryList)
            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = uri });
    }
}

感谢您的任何建议。

When I translated the Tester.WPF.resources.dll, I get an error. It's like the baml file have modified VisualStateGroup to an collection. I don't understand. The poject starts up without any problem in the default language, but if I change the culture, it crashes. I Rebuild it, still that error, even when a start from scratch. With this small test project and still get the same error:

Object of type 'System.Windows.VisualStateGroup' cannot be converted to type 'System.Collections.ObjectModel.Collection`1[System.Windows.VisualStateGroup]'.

StackTrace

    at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)   at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.SetClrComplexProperty(Object parentObject, MemberInfo memberInfo, Object o)
   at System.Windows.Markup.BamlRecordReader.SetPropertyValueToParent(Boolean fromStartTag, Boolean& isMarkupExtension)
   at System.Windows.Markup.BamlRecordReader.ReadElementEndRecord(Boolean fromNestedBamlRecordReader)
   at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
   at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
   at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
   at System.Windows.Markup.TreeBuilder.Parse()
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at Tester.WPF.Window1.InitializeComponent()

TestWindow

<Window x:Class="Arofex.Translator.Tester.WPF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
     xmlns:Controlsw="clr-namespace:System.Windows;assembly=WPFToolkit"
    >
<Grid>
    <Border x:Name="LayoutRoot"  BorderThickness="1" BorderBrush="Red" RenderTransformOrigin="0.5,0.5" Width="500" CornerRadius="5" Margin="0,0,0,30">
        <Border.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </Border.RenderTransform>
        <Controlsw:VisualStateManager.VisualStateGroups>
            <Controlsw:VisualStateGroup x:Name="VSGVisiblbe">
                <Controlsw:VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="00:00:00.2000000"/>
                </Controlsw:VisualStateGroup.Transitions>
                <Controlsw:VisualState x:Name="StateNormal"/>
                <Controlsw:VisualState x:Name="StateStart">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.034"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-57"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </Controlsw:VisualState>
            </Controlsw:VisualStateGroup>
        </Controlsw:VisualStateManager.VisualStateGroups>
        <StackPanel Orientation="Vertical" Background="LightGray">
            <TextBlock Text="My text to test translation" />

        </StackPanel>
    </Border>

App code

 private void Application_Startup(object sender, StartupEventArgs e)
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-BE");
        Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-BE");
        var dictionaryList = new List<Uri>();
        foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
            dictionaryList.Add(dictionary.Source);
        Application.Current.Resources.MergedDictionaries.Clear();
        foreach (Uri uri in dictionaryList)
            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = uri });
    }
}

Thanks for any suggestion.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文