删除设置后的XamlParseException(app.config)

时间:2012-11-08 06:10:50

标签: c# wpf xaml xamlparseexception

删除项目中的设置后,我得到了该异常。它是使用ProjectName.Properties命名空间的默认设置。我也从项目中删除了app.config。 为什么我这样做:我已经添加了序列化来读取我的settings.xml而不是旧版本。

我认为这些设置是在某处定义的,但不知道。

这是例外文本,如果它有帮助(在谷歌翻译中翻译):

  

调用类型为“GnomeExtractor.MainWindow”的构造函数,满足指定的绑定约束,导致异常。“行号”6“和”9“中的位置。

我删除了这些文件手动

  

Settings.settings
  Settings.Desighner.cs
  的app.config

我的MainWindow.xaml代码:

<Window ResxExtension.DefaultResxName="GnomeExtractor.Windows.MainWindow" Language="{UICulture}" 
        x:Class="GnomeExtractor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:GnomeExtractor"
        xmlns:dg="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
        Title="Gnome Extractor" Height="500" Width="1000" MinHeight="500" MinWidth="1000" Loaded="Window_Loaded" Closing="Window_Closing" Icon="/GnomeExtractor;component/Resources/GX icon.ico">
    <Window.Resources>
        <local:CellBackgroundColorConverter x:Key="CellBackgroundColorConverter" />
        <local:CellFocusableConverter x:Key="CellFocusableConverter" />
        <local:ColumnIndexToWidthConverter x:Key="ColumnIndexToWidthConverter" />
        <Style TargetType="DataGrid">
            <Setter Property="ItemsSource" Value="{Binding}" />
            <Setter Property="CanUserDeleteRows" Value="False" />
            <Setter Property="CanUserAddRows" Value="False" />
            <Setter Property="SelectionUnit" Value="Cell" />
            <Setter Property="RowHeaderWidth" Value="30" />
            <Setter Property="Margin" Value="5" />
            <Setter Property="SelectionMode" Value="Single" />
            <Setter Property="FrozenColumnCount" Value="8" />
            <Setter Property="MaxColumnWidth" Value="45" />
            <Setter Property="CanUserResizeColumns" Value="False" />
            <Setter Property="CanUserResizeRows" Value="False" />
        </Style>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="ToolTip" Value="" />
            <EventSetter Event="ToolTipOpening" Handler="DataGridColumnHeaderProfessions_ToolTipOpening" />
            <Setter Property="VerticalContentAlignment" Value="Bottom" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" Margin="5">
                            <TextBlock.LayoutTransform>
                                <RotateTransform Angle="-90" />
                            </TextBlock.LayoutTransform>
                        </TextBlock>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="DataGridCell">
            <Setter Property="Background">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource CellBackgroundColorConverter}" Mode="OneWay">
                        <Binding Path="Row[4]" />
                        <Binding Path="Row[5]" />
                        <Binding RelativeSource="{RelativeSource Self}" Path="Column.Header" />
                    </MultiBinding>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="Focusable" Value="{Binding Converter={StaticResource CellFocusableConverter}, RelativeSource={RelativeSource Self}, Path=Column.Header}"/>
            <EventSetter Event="PreviewMouseDown" Handler="DataGridCell_PreviewMouseDown" />
        </Style>
        <Style TargetType="DataGridRowHeader">
            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridRowHeader_PreviewMouseLeftButtonDown" />
        </Style>
        <Style TargetType="Image">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Opacity" Value="0.25" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

如果我删除了这个,我现在第5行出错,但下一个代码是我的样式,我可以悄悄地删除它,它没有任何效果。

我已将我的项目回滚到工作版本,并在删除app.config时出现此错误

UPD:我的MainWindow构造函数的工作代码

public MainWindow()
{
    // При первом запуске выставляем культуру установленную в компе, при последующих - предыдущую
    // First run changing localization same like in computer
    if (Settings.Default.ProgramLanguage == "")
    {
        string lang = "en-US";
        if (CultureInfo.InstalledUICulture.TwoLetterISOLanguageName == "ru")
            if (File.Exists("ru-RU\\GnomeExtractor.resources.dll")) lang = "ru-RU";

        CultureManager.UICulture = new CultureInfo(lang);
        Settings.Default.ProgramLanguage = lang;
    }
    else
        CultureManager.UICulture = new CultureInfo(Settings.Default.ProgramLanguage);

    CultureManager.UICultureChanged += new EventHandler(CultureManager_UICultureChanged);
    resourceManager = new ResourceManager("GnomeExtractor.Resources.Loc", Assembly.GetExecutingAssembly());

    //if (!File.Exists("loclib.dll")) MessageBox.Show("File loclib.dll not found, please reinstall the program");
    //if (!File.Exists("Gnomoria.exe")) MessageBox.Show("File Gnomoria.exe not found, please install the program in game folder");

    InitializeComponent();

    UpdateLanguageMenus();

    //Загружаем настроечки с прошлого запуска
    //Loading settings
    this.WindowState = Settings.Default.LastRunWindowState;
    this.Left = Settings.Default.LastRunLocation.X;
    this.Top = Settings.Default.LastRunLocation.Y;
    this.Width = Settings.Default.LastRunSize.Width;
    this.Height = Settings.Default.LastRunSize.Height;
    this.isCheatsOn = Settings.Default.LastRunCheatMode;
    this.isLabelsVertical = Settings.Default.LastRunIsLablesVertical;
    this.tabControl.SelectedIndex = Settings.Default.TabItemSelected;
    this.isAutoUpdateEnabled = Settings.Default.IsAutoUpdateEnabled;

    ControlStates();
}

小解释:Language = {UICulture} +绑定到{Resx值}(XAML)和CultureManager类(C#代码)是使用Resx文件进行本地化的库。
UpdateLanguageMenus()和ControlStates()仅用于IsEnable控件。

删除这些文件后,我替换了所有的Settings.Default。到我的新设置类(使用XML序列化),只需添加此代码

// Read settings from Xml file
settings.ReadXml();

/ UPD

如果您需要更多信息,请向我询问。

1 个答案:

答案 0 :(得分:0)

Woot,我发现了一个问题,这是一个很好的建议:https://stackoverflow.com/a/7857728/1808239

我的settings.Fields.ProgramLanguage是null,但不是“”