feat: selected item is now two-way binding by default.

This commit is contained in:
rabbitism
2024-04-17 20:35:35 +08:00
parent 2c471aa3f6
commit 50be089b4e
5 changed files with 73 additions and 27 deletions

View File

@@ -31,17 +31,22 @@
<u:TreeComboBox
Width="300"
HorizontalAlignment="Left"
SelectedItem="{Binding SelectedItem}"
ItemsSource="{Binding Items}">
<u:TreeComboBox.ItemTemplate>
<TreeDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding ItemName}" />
</TreeDataTemplate>
</u:TreeComboBox.ItemTemplate>
<u:TreeComboBox.SelectedItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemName}" />
</DataTemplate>
</u:TreeComboBox.SelectedItemTemplate>
</u:TreeComboBox>
<ContentControl Content="{Binding SelectedItem}">
<ContentControl.ContentTemplate>
<DataTemplate DataType="vm:TreeComboBoxItemViewModel">
<TextBlock Text="{Binding ItemName}"></TextBlock>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</StackPanel>
</UserControl>

View File

@@ -3,8 +3,9 @@ using CommunityToolkit.Mvvm.ComponentModel;
namespace Ursa.Demo.ViewModels;
public class TreeComboBoxDemoViewModel: ObservableObject
public partial class TreeComboBoxDemoViewModel: ObservableObject
{
[ObservableProperty] private TreeComboBoxItemViewModel? _selectedItem;
public List<TreeComboBoxItemViewModel> Items { get; set; }
public TreeComboBoxDemoViewModel()