在我的 UserControl 中,我使用了一个包含三个参数的 ListCollectionView。其中两个使用个性化的 RichTextBox 来解析 HTML。在此控件上,集合中的下一个/上一个项目有两个按钮。
我正在尝试在 ViewModel 中使用事件聚合器进行两项操作:
- 对于当前项,我需要在一个xml文件中写一个参数
- 对于当前项,我需要为两个 RichTextBox 重新初始化 htmlformatter
第一个操作:
public PopViewModel()
{
...
AlertData.CollectionChanged += (s, e) => AlertCollectionView.Refresh();
AlertCollectionView = new ListCollectionView(AlertData);
AlertCollectionView.MoveCurrentToPosition(0);
}
public void PreviousRecordExecute()
{
AlertCollectionView.MoveCurrentToPrevious();
}
public void NextRecordExecute()
{
AlertCollectionView.MoveCurrentToNext();
}
private Alert CurrentAlert
{
get { return AlertCollectionView.CurrentItem as Alert; }
set
{
AlertCollectionView.MoveCurrentTo(value);
NotifyOfPropertyChange();
}
}
public void MarkPopAlertAsRead(FeedItem CurrentAlert)
{
XElement doc = XElement.Load(diary);
XElement elementToChange=doc.Descendants("Alert")
.Single(x=>((int?)x.Element("key")==CurrentAlert.Alertid));
elementToChange.SetElementValue("IsRead","True");
doc.save(diary);
}
MarkPopAlertAsRead 是我需要与事件聚合器关联的方法。
第二个操作:
public partial class PopupView : UserControl
{
public PopupView()
{
InitializeComponent();
this.AlertTitleRichTextBox.TextFormatter = new HtmlFormatter();
this.AlertTxtRichTextBox.TextFormatter = new HtmlFormatter();
}
}
使用此代码,如果我更改了当前项目,这两个参数将从屏幕上消失,因此我需要重新加载 Textformatter。
和观点:
<uc:RichTextBox Margin="29,86,31,301" x:Name="AlertTitleRichTextBox" Text="{Binding AlertCollectionView/AlertTitle, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" Background="{x:Null}"/>
<TextBox Margin="257,378,10,12" Text="{Binding AlertCollectionView/AlertStartDate, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" Background="{x:Null}"/>
<uc:RichTextBox Margin="10,113,10,48" x:Name="AlertTxtRichTextBox" Text="{Binding AlertCollectionView/AlertText, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" Background="{x:Null}"/>
我的愿望是在集合更改时执行这两个操作(通过单击下一个/上一个按钮)。我需要一些实施帮助,因为 Caliburn Micro 文档对我没有帮助。