小编Kai*_*pka的帖子

Polyline使用DataBinding和PointCollection进行连续更新


首先,我描述了我想实现的目标.我希望可视化连续数据流(每秒最多1000个值,但可以减少).该数据流应该可视化为图表 - 更准确地说,它是ECG的可视化等.我的第一个想法是使用折线并将其绑定到点集合.这里的问题是UI上没有显示任何内容.也许对于这项任务来说,这是一个错误的方法.欢迎更好的想法.到目前为止,这是我的代码.首先是观点:

 
<Canvas>
  <Polyline Points="{Binding Points}" Stroke="Red" StrokeThickness="2" />
</Canvas>

为了简单起见,我使用代码隐藏,即使我使用MVVM模式.这也是我想要使用绑定而不仅仅是折线的名称并添加值的原因.


public partial class MainWindow : Window
{
   private short[] data = new short[]{ 10,30,50,70,90,110,130,150,170,190,210 };
   private short[] data1 = new short[] { 15,14,16,13,17,12,18,11,19,10,24 };

    public MainWindow()
    {
        InitializeComponent();
        for (int i = 0; i < data.Length; i++)
        {
            Points.Add(new Point(data[i], data1[i]));
        }
    }

    private PointCollection _points = new PointCollection();
    public PointCollection Points
    {
        get { return _points; }
    }
Run Code Online (Sandbox Code Playgroud)

我知道这不是一个好的编码风格,但对于我来说,首先测试它已经足够了.我将数组数据用于x值,将data1用于y值.任何人都可以告诉我这个绑定有什么问题吗?每当出现新值时,如何持续更新视图?
感谢您的帮助.

[更新的新版本]视图:


<Window.Resources>
        <my:PointCollectionConverter x:Key="myPointsConverter"/>
</Window.Resources>
    <Grid Name="grid"> …
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)

data-binding wpf polyline c#-4.0

5
推荐指数
2
解决办法
1万
查看次数

构造函数使用Unity/Prism/MVVM注入ObjectContext

我使用带有MVVM模式和Prism的WPF开发了一个应用程序.视图将添加到ModuleCatalog中,并且视图模型将注册到统一容器.为此,我正在使用一个负责创建shell的Bootstrapper,配置统一容器和模块目录.
现在的问题是,如何将我的EntityContext注入到几个视图模型中.
首先是Bootstrapper:

 
public class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            Shell shell = Container.Resolve();
            shell.Show();
            return shell;
        }

    protected override void ConfigureContainer()
    {
        base.ConfigureContainer();
        Container.RegisterType<EntityContext >("Context");
        Container.RegisterType<PersonViewModel>(new InjectionConstructor(
            new ResolvedParameter<EntityContext >("Context")));
    }

    protected override IModuleCatalog GetModuleCatalog()
    {
        ModuleCatalog catalog = new ModuleCatalog();
        catalog.AddModule(typeof(PersonModule));
        return catalog;
    }
Run Code Online (Sandbox Code Playgroud)

viewmodel看起来像那样(摘录)


public class PersonViewModel : ViewModelBase, IDataErrorInfo
    {
        private Person _person;
        private PersonRepository _repository;
        readonly EntityContext _context;

    public PersonViewModel(EntityContext context)
    {
        _context = context;
        _person = new Person();
        _repository = …
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection unity-container mvvm entity-framework-4

3
推荐指数
1
解决办法
5648
查看次数