Klonen funktioniert - MVVM komform

This commit is contained in:
2025-07-09 15:30:54 +02:00
parent 3aba7250d0
commit 7a96fba6d8
5 changed files with 61 additions and 23 deletions

View File

@@ -265,7 +265,7 @@
<CheckBox
Margin="4"
VerticalAlignment="Center"
IsChecked="{Binding IsChecked}" />
IsChecked="{Binding IsChecked, Mode=TwoWay}" />
<ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource AssistentMessageTemplate}" />
</StackPanel>

View File

@@ -14,6 +14,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:shared="clr-namespace:BS.Shared;assembly=BS.Shared"
xmlns:t="clr-namespace:BeWo.MultiLanguage.Markup"
xmlns:templateselectors="clr-namespace:BeWo.View.TemplateSelectors"
xmlns:uc="clr-namespace:BeWo.Controls;assembly=BeWo.Controls"
xmlns:viewmodel="clr-namespace:BeWo.ViewModel"
xmlns:vmv="clr-namespace:BeWo.ViewModel.View"
@@ -54,9 +55,9 @@
FontSize="14"
FontWeight="SemiBold"
Foreground="{DynamicResource TextForegroundPrimary}"
MouseDown="ConversationRenameTextBlock_MouseDown"
Text="{Binding Displayname}"
TextTrimming="CharacterEllipsis"
MouseDown="ConversationRenameTextBlock_MouseDown"
Visibility="{Binding IsEditing, Converter={StaticResource BoolVisibilityConverter}, ConverterParameter=false}" />
<TextBox
Margin="0"

View File

@@ -17,6 +17,8 @@ namespace BeWo.ViewModel
}
public event EventHandler IsCheckedChanged;
public bool IsChecked
{
get { return _IsChecked; }
@@ -27,6 +29,7 @@ namespace BeWo.ViewModel
_IsChecked = value;
FirePropertyChanged(nameof(IsChecked));
IsCheckedChanged?.Invoke(this, EventArgs.Empty);
}
}
@@ -61,5 +64,11 @@ namespace BeWo.ViewModel
return pDataContract;
}
public void SetIsChecked(bool value)
{
_IsChecked = value;
FirePropertyChanged(nameof(IsChecked));
}
}
}

View File

@@ -20,39 +20,67 @@ namespace BeWo.ViewModel.ListViewModel
{
public AiConversationMessageListVM(List<AiConversationMessageDC> pDCs) : base(pDCs)
{
VMList.ListChanged += (s, e) =>
{
if (e.ListChangedType == ListChangedType.ItemChanged)
{
var changedItem = VMList[e.NewIndex];
Item_PropertyChanged(changedItem, new PropertyChangedEventArgs(nameof(AiConversationMessageVM.IsChecked)));
}
};
foreach(var vm in VMList)
{
vm.IsCheckedChanged += CloneIsCheckedChanged;
}
//VMList.ListChanged += (s, e) =>
// {
// if (e.ListChangedType == ListChangedType.ItemChanged)
// {
// var changedItem = VMList[e.NewIndex];
// Item_PropertyChanged(changedItem, new PropertyChangedEventArgs(nameof(AiConversationMessageVM.IsChecked)));
// }
// };
}
public AiConversationMessageListVM() : this(null) { }
private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
private void CloneIsCheckedChanged(object sender, EventArgs e)
{
if (e.PropertyName == nameof(AiConversationMessageVM.IsChecked)
&& sender is AiConversationMessageVM vm
&& vm.Role == BS.Shared.AiConversationMessageRole.Assistent)
if(sender is AiConversationMessageVM vm)
{
var changedItem = (AiConversationMessageVM)sender;
int index = VMList.IndexOf(changedItem);
int index = VMList.IndexOf(vm);
if (changedItem.IsChecked)
if (vm.IsChecked)
{
for (int i = 0; i <= index; i++)
if (!VMList[i].IsChecked)
VMList[i].IsChecked = true;
for (int i = 0; i < index; i++)
{
VMList[i].SetIsChecked(true);
}
}
else
{
for (int i = index - 1; i < VMList.Count; i++)
if (VMList[i].IsChecked)
VMList[i].IsChecked = false;
{
VMList[i].SetIsChecked(false);
}
}
}
}
//private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
//{
// if (e.PropertyName == nameof(AiConversationMessageVM.IsChecked)
// && sender is AiConversationMessageVM vm
// && vm.Role == BS.Shared.AiConversationMessageRole.Assistent)
// {
// var changedItem = (AiConversationMessageVM)sender;
// int index = VMList.IndexOf(changedItem);
// if (changedItem.IsChecked)
// {
// for (int i = 0; i <= index; i++)
// if (!VMList[i].IsChecked)
// VMList[i].IsChecked = true;
// }
// else
// {
// for (int i = index - 1; i < VMList.Count; i++)
// if (VMList[i].IsChecked)
// VMList[i].IsChecked = false;
// }
// }
//}
}
}

View File

@@ -346,7 +346,7 @@ namespace BeWo.ViewModel.View
{
foreach (var message in ListVM.SelectedVM.Messages.VMList)
{
message.IsChecked = true;
message.SetIsChecked(true);
}
IsCloneOpen = true;