Help with possible bug in TabViewItem setting AvaloniaEdit editor as Content #216
Replies: 2 comments
-
|
As someone who isn't an MVVM expert or "purist", I'm not the best person to offer MVVM advice, but looking at the code I see some issues. First though, thanks for the video and repro. Remember that MVVM is about separation of backend logic and the UI, which you seem to be mixing (which is fine, MVVM take a bit of getting used to). I'd recommend restructuring some things. Again, not a MVVM expert so there may be even better ways to do some of this, but this should at least get you on the right track and at least resolve your issue.
public class DocumentItem
{
public string? Header { get; set; }
public IconSource? IconSource { get; set; }
public TextDocument Document { get; set; } // Do this instead
public CodeEditorView? Content { get; set; } // Don't do this
public bool Selected { get; set; }
}In Documents.Add(new DocumentItem
{
Document = new AvaloniaEdit.Document.TextDocument(),
// other properties
});I noticed you're also focusing the TextArea after this too. You'll have to find a different way to do that. Options include behaviors, using an event or property change notification on the TabView to detect when the tab is opened, or you can handle Finally, to make it work: in <ui:TabView.TabItemTemplate>
<DataTemplate x:DataType="mod:DocumentItem">
<ui:TabViewItem Header="{CompiledBinding Header}"
IconSource="{CompiledBinding IconSource}"
IsSelected="{CompiledBinding Selected}"
Content="{CompiledBinding }">
<ui:TabViewItem.ContentTemplate>
<DataTemplate DataType="mod:DocumentItem">
<aedit:TextEditor Document="{CompiledBinding Document}"
Name="Editor"
FontFamily="Cascadia Code,Consolas,Menlo,Monospace"
Margin="30"
Foreground="#D4D4D4"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Visible"
FontWeight="Bold"
FontSize="18" ShowLineNumbers="True" />
</DataTemplate>
</ui:TabViewItem.ContentTemplate>
</ui:TabViewItem>
</DataTemplate>
</ui:TabView.TabItemTemplate>After this, you should see that the issue you described after dragging the tab no longer happens. I hope this helps. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the thorough response, you have no idea how helpful it is to me while trying to understand as much as possible. Regarding the original bug, as you said it has been fixed 😁. I have a question: if DocumentItem should be a ViewModel, to what view should it correspond? Do you suggest wrapping the entire TabViewItem with the icon, header and editor as a view to be used inside |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello guys, it's my first time attempting MVVM seriously and it's being great so far.
I'm using Avalonia 2.0.0-preview2 and all of the other packages as well as FluentAvalonia are also the latest preview release.
This also happened with the stable 0.10.18 version of Avalonia and FluentAvalonia
I've encountered this situation while trying to host TextEditors from AvaloniaEdit into TabViewItems... As you can see, when I grab a tab and move it around, the editor inside the TabViewItem breaks...
This does not happen if I set the content to be a string for example, it still shows correctly despite shuffling tabs around.
My code is https://github.com/maxijabase/Avalia
(adding document method: https://github.com/maxijabase/Avalia/blob/master/Avalia/ViewModels/EditorManagerViewModel.cs#L23-L33)
(code editor control: https://github.com/maxijabase/Avalia/blob/master/Avalia/Views/CodeEditorView.axaml)
Please let me know if my implementation is wrong, if you need more details or whatever, I'll happily assist and provide.
devenv_ZnuQV3jAYl.mp4
Beta Was this translation helpful? Give feedback.
All reactions