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

时间:2010-09-13 08:11:26

标签: c# wpf localization wpftoolkit locbaml

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

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

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

感谢您的任何建议。

0 个答案:

没有答案