1

当我翻译 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]'.

堆栈跟踪

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

测试窗口

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

感谢您的任何建议。

4

0 回答 0