コード例 #1
0
    protected void UpdateMods()
    {
        foreach (KeyValuePair <string, Mod> kv in Mod.Mods)
        {
            bool         add       = true;
            ModViewModel alreadyVM = null;
            foreach (ListViewItem i in _Mods)
            {
                ModViewModel vm = ((ModViewModel)i.DataContext);
                if (vm.versions.Values.Contains(kv.Value))
                {
                    add = false;
                }
                if (vm.ID == kv.Value.ID)
                {
                    alreadyVM = vm;
                }
            }
            if (add)
            {
                Mod mod = kv.Value;
                if (alreadyVM != null)
                {
                    alreadyVM.versions.Add(Mod.Header.ParseModVersion(mod.header.GetVersion()), mod);
                    alreadyVM.OnPropertyChanged("Version");
                    alreadyVM.OnPropertyChanged("Name");
                }
                else
                {
                    ListViewItem item = new ListViewItem();

                    StackPanel outerPanel = new StackPanel();
                    outerPanel.Orientation = Orientation.Horizontal;
                    outerPanel.Margin      = new Thickness(-5, 0, 0, 0);
                    CheckBox checkBox = new CheckBox();
                    checkBox.SetBinding(CheckBox.IsCheckedProperty, "Selected");
                    outerPanel.Children.Add(checkBox);

                    StackPanel panel = new StackPanel();

                    TextBlock textBlock = new TextBlock();
                    textBlock.SetBinding(TextBlock.TextProperty, "Name");
                    textBlock.Style = (Style)Application.Current.FindResource("HeaderLabel");

                    panel.Children.Add(textBlock);

                    TextBlock textBlock2 = new TextBlock();
                    textBlock2.SetBinding(TextBlock.TextProperty, "Version");
                    textBlock2.FontSize = 12;
                    textBlock2.Style    = (Style)Application.Current.FindResource("NormalLabel");
                    panel.Children.Add(textBlock2);
                    outerPanel.Children.Add(panel);

                    ModViewModel mvm = new ModViewModel(mod);
                    item.DataContext = mvm;
                    item.Content     = outerPanel;
                    _Mods.Add(item);
                }
            }
        }

        foreach (ListViewItem item in _Mods)
        {
            ModViewModel vm = (ModViewModel)item.DataContext;
            vm.Initialized();
        }
        _FirstBatchLoaded = true;
        if (_SelectNewestModVersions)
        {
            SelectNewestVersions();
        }
    }