Drag & Drop only for moving items
This commit is contained in:
@@ -6,9 +6,6 @@ namespace ReceiptPDFBuilder.Models;
|
||||
|
||||
class ReportFile : ChangeNotifier
|
||||
{
|
||||
private bool _isMoveUpEnabled = false;
|
||||
private bool _isMoveDownEnabled = false;
|
||||
|
||||
private string _title;
|
||||
private DateOnly _date;
|
||||
private DateTime _dateTime;
|
||||
@@ -78,16 +75,4 @@ class ReportFile : ChangeNotifier
|
||||
{
|
||||
get => Path.GetFileName(_filePath);
|
||||
}
|
||||
|
||||
public bool IsMoveUpEnabled
|
||||
{
|
||||
get => _isMoveUpEnabled;
|
||||
set { _isMoveUpEnabled = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public bool IsMoveDownEnabled
|
||||
{
|
||||
get => _isMoveDownEnabled;
|
||||
set { _isMoveDownEnabled = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
}
|
||||
@@ -95,26 +95,14 @@ class MainViewModel : BaseViewModel, IFontResolver
|
||||
Date = DateOnly.FromDateTime(File.GetCreationTime(filePath)),
|
||||
Notes = "",
|
||||
FilePath = filePath,
|
||||
IsMoveDownEnabled = true,
|
||||
IsMoveUpEnabled = true,
|
||||
});
|
||||
}
|
||||
}
|
||||
UpdateMoveEnabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateMoveEnabled()
|
||||
{
|
||||
for (var i = 0; i < ReportFiles.Count; i++)
|
||||
{
|
||||
ReportFiles[i].IsMoveUpEnabled = i != 0;
|
||||
ReportFiles[i].IsMoveDownEnabled = i != ReportFiles.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveItemUp(ReportFile file)
|
||||
{
|
||||
var idx = ReportFiles.IndexOf(file);
|
||||
@@ -127,7 +115,6 @@ class MainViewModel : BaseViewModel, IFontResolver
|
||||
// So, remove and insert.
|
||||
ReportFiles.RemoveAt(idx);
|
||||
ReportFiles.Insert(idx - 1, file);
|
||||
UpdateMoveEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +125,6 @@ class MainViewModel : BaseViewModel, IFontResolver
|
||||
{
|
||||
ReportFiles.RemoveAt(idx);
|
||||
ReportFiles.Insert(idx + 1, file);
|
||||
UpdateMoveEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +137,6 @@ class MainViewModel : BaseViewModel, IFontResolver
|
||||
if (idx != -1)
|
||||
{
|
||||
ReportFiles.RemoveAt(idx);
|
||||
UpdateMoveEnabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-19
@@ -66,9 +66,10 @@
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Title"
|
||||
Binding="{Binding Title}"
|
||||
IsReadOnly="True"
|
||||
Width="*"/>
|
||||
<DataGridTemplateColumn Header="Receipt Date"
|
||||
IsReadOnly="False"
|
||||
IsReadOnly="True"
|
||||
Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
@@ -96,27 +97,12 @@
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Spacing="4">
|
||||
<Button Command="{Binding $parent[DataGrid].((vm:MainViewModel)DataContext).MoveItemUp}"
|
||||
CommandParameter="{Binding}"
|
||||
IsEnabled="{Binding IsMoveUpEnabled}">
|
||||
<Button.Content>
|
||||
<Label Content="" FontFamily="{StaticResource FontAwesomeSolid}" />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button Content="Down"
|
||||
Command="{Binding $parent[DataGrid].((vm:MainViewModel)DataContext).MoveItemDown}"
|
||||
CommandParameter="{Binding}"
|
||||
IsEnabled="{Binding IsMoveDownEnabled}">
|
||||
<Button.Content>
|
||||
<Label Content="" FontFamily="{StaticResource FontAwesomeSolid}" />
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button Content="Byebye"
|
||||
Command="{Binding $parent[DataGrid].((vm:MainViewModel)DataContext).RemoveFile}"
|
||||
<Button Command="{Binding $parent[DataGrid].((vm:MainViewModel)DataContext).RemoveFile}"
|
||||
CommandParameter="{Binding}"
|
||||
Margin="2"
|
||||
IsEnabled="True">
|
||||
<Button.Content>
|
||||
<Label Content="" FontFamily="{StaticResource FontAwesomeSolid}" />
|
||||
<TextBlock><Run Text="" FontFamily="{StaticResource FontAwesomeSolid}"/> Remove Item</TextBlock>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
Reference in New Issue
Block a user