Şu kodlarımda Checbox yerine toggle switch kullanalım <Page…
- User
Şu kodlarımda Checbox yerine toggle switch kullanalım <ui:Button Height="50" CornerRadius="12" Background="Transparent" Content="Kaydet" Click="SaveButton_Click" Margin="5"/> <ui:TreeViewItem Header="Kategori 1"> </ui:TreeViewItem> <ui:TreeViewItem Header="Kategori 2"> </ui:TreeViewItem> using System.IO; using System.Collections.Generic; using Microsoft.Win32; using Microsoft.Dism; using System.Text.Json; using ShadesToolkit.ViewModels.Pages; using Wpf.Ui.Controls; using System.Diagnostics; using System.ComponentModel; using System.Collections.ObjectModel; using System.Globalization; using System.Windows.Media; using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel; using System.Text; using System.Windows.Controls; using TreeViewItem = System.Windows.Controls.TreeViewItem;
namespace ShadesToolkit.Views.Pages { public partial class ExtraDebloat : INavigableView { private string MountFolder = Path.Combine(Path.GetTempPath(), "MountFolder");
public ExtraDebloatViewModel ViewModel { get; } private readonly Dictionary<CheckBox, List<string>> checkBoxScripts = new Dictionary<CheckBox, List<string>>(); public ExtraDebloat(ExtraDebloatViewModel viewModel) { ViewModel = viewModel; DataContext = this; InitializeComponent(); checkBoxScripts.Add(OneDrive, new List<string> { "for /f \"delims=\" %%i in ('dir /s /b /ad \"%InstallDir%\\*OneDrive*\"') do (\r\n if exist \"%%i\" (\r\n %MinSudo% --TrustedInstaller --Verbose --Privileged --NoLogo --WorkDir=\"\" cmd /c \"rmdir /s /q \"%%i\"\"\r\n )\r\n)", }); checkBoxScripts.Add(iki, new List<string> { "echo Batch Script 2" }); checkBoxScripts.Add(uc, new List<string> { "echo Batch Script 3" }); checkBoxScripts.Add(dort, new List<string> { "echo Batch Script 4" }); } private void SaveButton_Click(object sender, RoutedEventArgs e) { StringBuilder scriptContent = new StringBuilder(); // Bat dosyasının en başına "echo off" ekler scriptContent.AppendLine("@echo off"); scriptContent.AppendLine("set InstallDir=C:\\Users\\%USERNAME%\\AppData\\Local\\Temp\\MountFolder"); // Her bir TreeViewItem için işleme foreach (TreeViewItem treeViewItem in treeView.Items) { ProcessTreeViewItem(treeViewItem, scriptContent); } if (scriptContent.Length > "@echo off".Length + Environment.NewLine.Length) { SaveScriptToFile(scriptContent.ToString()); } else { MessageBox.Show("Hiçbir komut seçilmedi."); } } private void ProcessTreeViewItem(ItemsControl itemsControl, StringBuilder scriptContent) { foreach (object obj in itemsControl.Items) { TreeViewItem subItem = itemsControl.ItemContainerGenerator.ContainerFromItem(obj) as TreeViewItem; if (subItem != null) { // Alt TreeViewItem’ı işle ProcessTreeViewItem(subItem, scriptContent); } CheckBox checkBox = obj as CheckBox; if (checkBox != null && checkBox.IsChecked == true) { List<string> scripts; if (checkBoxScripts.TryGetValue(checkBox, out scripts)) { // CheckBox’a karşılık gelen tüm batch komutlarını sözlükten al ve ekleyebiliriz. foreach (string script in scripts) { scriptContent.AppendLine(script); } } } } } private void SaveScriptToFile(string content) { string filePath = "tweaker.bat"; File.WriteAllText(filePath, content); MessageBox.Show(filePath + " kaydedildi."); } } - Assistant
- User
tam kodu ver
- Assistant