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