I've added a RichTextBox
and a ToolBar
in my DropBox
and noticed a few more issues.
1) When I select text in RichTextBox and click on Bold icon, it changes the selected text's style but the Bold Icon remains in Focus/Highlighted (changes from black to blue and remains blue until I click on another ToolButton) even if I change style with keyboard shortcut (Ctrl+B). This is the behavior for all ToolBar Icons
2) By default I can't drop file(s) on RichTextBox. I've tried hooking up an event like this:
message = (RichTextBox)GetTemplateChild("message");
message.DragOver += OnDragOverMessage;
But this DragOver
doesn't work, I've to add the handler this way:
message.AddHandler(DragOverEvent, new DragEventHandler(OnDragOverMessage), true);
the last true
argument is the key to make it work and in addition to that I've to have these in my eventhandler:
void OnDragOverMessage(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effects = DragDropEffects.Copy;
else e.Effects = DragDropEffects.None;
}
Now with these in OnDragOverMessage
, it allows dropping files as well as folder! To prevent folder drop, I've to have a check for FileAttributes
in OnDrop
function:
protected override void OnDrop(DragEventArgs e)
{
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files)
{
if (File.GetAttributes(file).HasFlag(FileAttributes.Directory)) continue;
Collection.Add(new(file, file.Substring(file.LastIndexOf('\\') + 1), new FileInfo(file).Length));
}
}

I've uploaded a .zip
file BUT not sure whether it's been uploaded or not, I don't see that when I go to the link provided! Do you see that?