我正在WPF中的一个项目,每秒更新视图30次.据我所知,我正在使用MVVM模式,并且对目前的结果非常满意.但是,我想知道是否有更有效的方法来更新我的主机容器中的VisualCollection内的DrawingVisuals.在我的viewmodel中的每个属性更改中,我发现,删除然后为该viewmodel重新添加一个新的DrawingVisual.随着不断移动的对象,我觉得应该有更好的方法,比如将DrawingVisuals本身直接绑定到viewmodel的属性,但是看起来会是什么样的?随着模拟中模型数量的增长,我需要确保我有一个简化的更新工作流程.我开始按照这里的示例开始:http://msdn.microsoft.com/en-us/library/ms742254.aspx
我故意避免使用DependencyProperties并将UserControls绑定到每个viewmodel,因为我需要一个非常有效的绘图画布(因此下面的QuickCanvas).因此除了设计主UI和连接按钮和命令之外,我几乎不需要XAML.请问是否有些事情似乎不清楚或者我遗漏了一些重要的事情.谢谢!
可视主机容器(视图):
public partial class QuickCanvas : FrameworkElement
{
private readonly VisualCollection _visuals;
private readonly Dictionary<Guid, DrawingVisual> _visualDictionary;
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(ObservableNotifiableCollection<IVisualModel>),
typeof(QuickCanvas),
new PropertyMetadata(OnItemsSourceChanged));
public QuickCanvas()
{
InitializeComponent();
_visuals = new VisualCollection(this);
_visualDictionary = new Dictionary<Guid, DrawingVisual>();
}
public ObservableNotifiableCollection<IVisualModel> ItemsSource
{
set { SetValue(ItemsSourceProperty, value); }
get { return (ObservableNotifiableCollection<IVisualModel>)GetValue(ItemsSourceProperty); }
}
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property.Name == "Width" || e.Property.Name == "Height" || e.Property.Name == …Run Code Online (Sandbox Code Playgroud)