Frage

I get that exception, after deleting settings in my project. It is a default settings that using ProjectName.Properties namespace. Also i deleted app.config from project. Why i did that: i have been added serialize for reading my settings.xml instead of the old version.

I think these settings are defined somewhere, but dont know it.

This is text of exception, if it helps (translated in google translate):

Call the constructor for type" GnomeExtractor.MainWindow ", satisfying the specified binding constraints, led to an exception." Row number "6" and the position in the "9."

I deleted these files manually:

Settings.settings
Settings.Desighner.cs
app.config

My MainWindow.xaml code:

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

If i delete this, i got error in row 5 now, but next code is my styles and i can quietly delete this and it did not has no effect.

I have rolled back my project to working version, and got this error when i delete app.config

UPD: My MainWindow constructor's worked code

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

Little explanation: Language={UICulture} + binding to a {Resx value} (XAML) and CultureManager class (C# code) is a lib for localization, using Resx files.
UpdateLanguageMenus() and ControlStates() just for a IsEnable controlling.

After deleting these files i replaced all of Settings.Default. to my new class of settings (using XML serialization) and just added this code

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

/UPD

If you need more information, ask me about, please.

War es hilfreich?

Lösung

Woot, i found a problem, this is a good advice: https://stackoverflow.com/a/7857728/1808239

My settings.Fields.ProgramLanguage was a null, but not a ""

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top