Загрузка данных


jdjdjdjdjdjf

<Button x:Name="RenameButton" Click="RenameButton_Click" Style="{StaticResource SideMenuButton}">
    <StackPanel Orientation="Horizontal">
        <materialDesign:PackIcon Kind="RenameBox" Width="20" Height="20" Margin="0,0,12,0"
                                 Foreground="{DynamicResource MaterialDesign.Brush.Primary}"/>
        <TextBlock Text="Переименовать" VerticalAlignment="Center"/>
    </StackPanel>
</Button>



private void RenameButton_Click(object sender, RoutedEventArgs e)
{
    if (FilesListView.SelectedItem is not FileItem item)
    {
        MessageBox.Show("Выберите файл или папку.");
        return;
    }

    var dialog = new Window
    {
        Title = "Переименовать",
        Width = 380,
        Height = 160,
        WindowStartupLocation = WindowStartupLocation.CenterOwner,
        Owner = this,
        ResizeMode = ResizeMode.NoResize,
        Background = Background
    };

    var panel = new StackPanel { Margin = new Thickness(16) };
    var tb = new System.Windows.Controls.TextBox
    {
        Text = item.Name,
        Margin = new Thickness(0, 0, 0, 12),
        Style = (Style)FindResource("MaterialDesignOutlinedTextBox")
    };
    var btnOk = new System.Windows.Controls.Button
    {
        Content = "Переименовать",
        Style = (Style)FindResource("MaterialDesignRaisedButton"),
        HorizontalAlignment = HorizontalAlignment.Right,
        Width = 140
    };

    btnOk.Click += (_, _) =>
    {
        string newName = tb.Text.Trim();
        if (string.IsNullOrEmpty(newName))
        {
            MessageBox.Show("Введите имя.");
            return;
        }

        if (newName == item.Name)
        {
            dialog.Close();
            return;
        }

        string newPath = IOPath.Combine(currentPath, newName);

        if (File.Exists(newPath) || Directory.Exists(newPath))
        {
            MessageBox.Show("Файл или папка с таким именем уже существует.");
            return;
        }

        try
        {
            if (item.IsDirectory)
                Directory.Move(item.FullPath, newPath);
            else
                File.Move(item.FullPath, newPath);

            dialog.Close();
            LoadDirectory(currentPath);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Ошибка переименования");
        }
    };

    panel.Children.Add(tb);
    panel.Children.Add(btnOk);
    dialog.Content = panel;
    tb.SelectAll();
    tb.Focus();
    dialog.ShowDialog();
}

jdjdjdjdj