Пример #1
0
        protected override void RegisterTypes()
        {
            var translationManager = new TranslationManager();
            var logManager         = new LogManager();

            this.Container.RegisterInstance <ITranslationManager>(translationManager);
            this.Container.RegisterInstance <ITranslationService>(new TranslationService(translationManager));
            this.Container.RegisterInstance <ILogManager>(logManager);
#if DEBUG
            this.Container.RegisterInstance <ILogger>(new Logger(logManager, LogSeverity.Debug));
#else
            this.Container.RegisterInstance <ILogger>(new Logger(logManager, LogSeverity.Error));
#endif
            this.Container.RegisterInstance <IMasterDetailNavigationService>(new MasterDetailNavigationService());
            TranslationConverter.RegisterInstance(this.Container.Resolve <TranslationConverter>());

            this.Container.RegisterTypeForNavigation <NavigationPage>();

            this.Container.RegisterViewForMasterDetailNavigation <LogPage, LogViewModel>(new LogDisplayableToken());
        }
        /// <summary>
        /// Add new translation row (a panel with respective elements) to the dialog.
        /// </summary>
        private void AddTranslationRow(Translation tr)
        {
            var copy         = (FrameworkElement)XamlReader.Parse(XamlWriter.Save(translationRow));
            int addButtonIdx = translationsPanel.Children.IndexOf(addTranslationBtn);

            copy.Name       = null; //To show that it's a new item
            copy.Visibility = Visibility.Visible;
            copy.Tag        = tr;

            var newTranslationLbl = (TextBlock)copy.FindName(nameof(translationLbl));

            newTranslationLbl.Text     = TranslationConverter.ConvertToString(tr);
            newTranslationLbl.MouseUp += (s, e) =>
            { //Edit the translation
                var dlg = new TranslationsEditDlg(tr.Text, tr.Part)
                {
                    Owner = this
                };

                if (dlg.ShowDialog() == true)
                {
                    tr.Text = dlg.Translation.Value.translation;
                    tr.Part = dlg.Translation.Value.partOfSpeech;

                    newTranslationLbl.Text = TranslationConverter.ConvertToString(tr);

                    ChangesHaveBeenMade();
                }
            };

            var newRemoveBtn = (Button)copy.FindName(nameof(trRemoveBtn));

            newRemoveBtn.Click += (s, e) =>
            { //Remove the translation
                LooseHeight();

                translationsPanel.Children.Remove(copy);
                translations.Remove(tr);

                FixHeight();

                countOfShownTranslations--;
                UpdateAddButtonState();
                UpdateTranslationsArrowsState();
                ChangesHaveBeenMade();
            };

            var newTrUpBtn = (Button)copy.FindName(nameof(trUpBtn));

            newTrUpBtn.Click += (s, e) => MoveTranslationRow(copy, moveUp: true);

            var newTrDownBtn = (Button)copy.FindName(nameof(trDownBtn));

            newTrDownBtn.Click += (s, e) => MoveTranslationRow(copy, moveUp: false);

            LooseHeight();

            translationsPanel.Children.Insert(addButtonIdx, copy);

            if (Visibility == Visibility.Visible) //Only if form is already shown and knows its size
            {
                FixHeight();
            }

            countOfShownTranslations++;
            UpdateAddButtonState();
        }