Best way to show dynamic changes on Image in Gridview with MVVM

I would like to show several Images in an Gridview and show on this picture some circles like an overlay.For Example show several rooms and do circles in different places for lamps or outlets and change color, if the state changed. I made an prototype with an big canvas, uses several images and then place this “dots” with coordinates.

Now i created an model with an string for the path of the image and a List with items (own class with x,y,color) for several dots. I created an itemcontrol with an canvas, set the picture as Background an now i would like to make circles or dots for every point in this list.

<ItemsControl ItemsSource="{Binding Intersections}" FontFamily="Bahnschrift" Margin="10,10,10,10" AutomationProperties.IsRowHeader="False" BorderThickness="0,0,0,0" Background="#A5FFFFFF" BorderBrush="{x:Null}" >
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="2" VerticalAlignment="Top" MinHeight="500"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Canvas Width="200" Height="200" >
                <Canvas.Background>
                    <ImageBrush ImageSource="{Binding MapPath}" />
                </Canvas.Background>                    
            </Canvas>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
internal class Intersection
{
    private String _mapPath;
    public String MapPath
    {
        get
        {
            return _mapPath;
        }
        set
        {
            _mapPath = value;
        }
    }
    public String Name;
    public List<Signals> Signals;

    public Intersection(String name, String mapPath)
    {
        this.Name = name;
        this.MapPath = mapPath;
        Signals = new List<Signals>();
    }

    public void AddSignal(Signals signals)
    {
        Signals.Add(signals);
    }

}
internal class Signals
{
    public int SignalX = 0;
    public int SignalY = 0;
    public Color ColorOn = Color.Green;
    public Color ColorOff = Color.Red;

    public Signals(int x, int y)
    {
        SignalX = x;
        SignalY = y;
    }
}

How can i draw the dots on every picture and how am i able to update this? Or is there an better way to do this?

Here is an example from my prototyp.
enter image description here

Later the user should be able to change row and columns to fit this layout to their screen.

Edit: Here do I insert testdata

 private ObservableCollection<Intersection> _intersections;
    public IEnumerable<Intersection> Intersections => 
    _intersections;


    public HomeViewModel(DataStore dataStore)
    {
    this.dataStore = dataStore;
    _intersections = new ObservableCollection<Intersection>();
    Intersection test1 = new Intersection("test1", 
    "/test/testknoten107.png");
    Intersection test2 = new Intersection("test2", 
    "/test/testknoten108.png");
    
    test1.AddSignal(new Signals(400, 400));
    test1.AddSignal(new Signals(100, 100));
    test1.AddSignal(new Signals(2000, 2000));
    test1.AddSignal(new Signals(300, 300));
    
    test2.AddSignal(new Signals(100, 100));
    test2.AddSignal(new Signals(100, 200));
    test2.AddSignal(new Signals(200, 100));
    test2.AddSignal(new Signals(200, 200));
    _intersections.Add(test1);
    _intersections.Add(test2);
    }

With the solution from Tarazed I got the most of the behaviour I want. Now the only problem is, that the dots, they supposed to be over the map, are in the top-left corner.

Red Dot stuck in corner

New contributor

Matt Hias is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Since you have a collection inside elements of another collection, you will have to nest a Signals ItemsControl inside the DataTemplate of the Intersections ItemsControl. If you use a Grid with no columns or rows, you can stack the new ItemsControl on top of the background image (which might no longer need a canvas, you could probably just use an Image).

<ItemsControl ItemsSource="{Binding Intersections}" FontFamily="Bahnschrift" Margin="10,10,10,10" AutomationProperties.IsRowHeader="False" BorderThickness="0,0,0,0" Background="#A5FFFFFF" BorderBrush="{x:Null}" >
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <UniformGrid Columns="2" VerticalAlignment="Top" MinHeight="500"/>
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
    
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <Grid>
        <Image Source="{Binding MapPath}"/>
          
        <ItemsControl ItemsSource="{Binding Signals}" >
          <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
              <Canvas />
            </ItemsPanelTemplate>
          </ItemsControl.ItemsPanel>
            
          <ItemsControl.ItemTemplate>
            <DataTemplate>
              <Ellipse Canvas.Left="{Binding SignalX}" Canvas.Top="{Binding SignalY}" Width="5" Height="5"/>
            </DataTemplate>
          </ItemsControl.ItemTemplate>
        </ItemsControl>
      </Grid>
    </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>

As a side note, I also advise against using accessible fields. Anything that can be a public field can be a property easily. Even if it’s just an auto-property, it will save you a lot of trouble down the road. Keep those fields private… always.

public int SignalX { get; }
public int SignalY { get; }
public Color ColorOn { get; } = Color.Green;
public Color ColorOff { get; } = Color.Red;
public string Name { get; }
public List<Signals> Signals { get; } = new();

8

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Best way to show dynamic changes on Image in Gridview with MVVM

I would like to show several Images in an Gridview and show on this picture some circles like an overlay.For Example show several rooms and do circles in different places for lamps or outlets and change color, if the state changed. I made an prototype with an big canvas, uses several images and then place this “dots” with coordinates.

Now i created an model with an string for the path of the image and a List with items (own class with x,y,color) for several dots. I created an itemcontrol with an canvas, set the picture as Background an now i would like to make circles or dots for every point in this list.

<ItemsControl ItemsSource="{Binding Intersections}" FontFamily="Bahnschrift" Margin="10,10,10,10" AutomationProperties.IsRowHeader="False" BorderThickness="0,0,0,0" Background="#A5FFFFFF" BorderBrush="{x:Null}" >
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="2" VerticalAlignment="Top" MinHeight="500"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Canvas Width="200" Height="200" >
                <Canvas.Background>
                    <ImageBrush ImageSource="{Binding MapPath}" />
                </Canvas.Background>                    
            </Canvas>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
internal class Intersection
{
    private String _mapPath;
    public String MapPath
    {
        get
        {
            return _mapPath;
        }
        set
        {
            _mapPath = value;
        }
    }
    public String Name;
    public List<Signals> Signals;

    public Intersection(String name, String mapPath)
    {
        this.Name = name;
        this.MapPath = mapPath;
        Signals = new List<Signals>();
    }

    public void AddSignal(Signals signals)
    {
        Signals.Add(signals);
    }

}
internal class Signals
{
    public int SignalX = 0;
    public int SignalY = 0;
    public Color ColorOn = Color.Green;
    public Color ColorOff = Color.Red;

    public Signals(int x, int y)
    {
        SignalX = x;
        SignalY = y;
    }
}

How can i draw the dots on every picture and how am i able to update this? Or is there an better way to do this?

Here is an example from my prototyp.
enter image description here

Later the user should be able to change row and columns to fit this layout to their screen.

Edit: Here do I insert testdata

 private ObservableCollection<Intersection> _intersections;
    public IEnumerable<Intersection> Intersections => 
    _intersections;


    public HomeViewModel(DataStore dataStore)
    {
    this.dataStore = dataStore;
    _intersections = new ObservableCollection<Intersection>();
    Intersection test1 = new Intersection("test1", 
    "/test/testknoten107.png");
    Intersection test2 = new Intersection("test2", 
    "/test/testknoten108.png");
    
    test1.AddSignal(new Signals(400, 400));
    test1.AddSignal(new Signals(100, 100));
    test1.AddSignal(new Signals(2000, 2000));
    test1.AddSignal(new Signals(300, 300));
    
    test2.AddSignal(new Signals(100, 100));
    test2.AddSignal(new Signals(100, 200));
    test2.AddSignal(new Signals(200, 100));
    test2.AddSignal(new Signals(200, 200));
    _intersections.Add(test1);
    _intersections.Add(test2);
    }

With the solution from Tarazed I got the most of the behaviour I want. Now the only problem is, that the dots, they supposed to be over the map, are in the top-left corner.

Red Dot stuck in corner

New contributor

Matt Hias is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Since you have a collection inside elements of another collection, you will have to nest a Signals ItemsControl inside the DataTemplate of the Intersections ItemsControl. If you use a Grid with no columns or rows, you can stack the new ItemsControl on top of the background image (which might no longer need a canvas, you could probably just use an Image).

<ItemsControl ItemsSource="{Binding Intersections}" FontFamily="Bahnschrift" Margin="10,10,10,10" AutomationProperties.IsRowHeader="False" BorderThickness="0,0,0,0" Background="#A5FFFFFF" BorderBrush="{x:Null}" >
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <UniformGrid Columns="2" VerticalAlignment="Top" MinHeight="500"/>
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
    
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <Grid>
        <Image Source="{Binding MapPath}"/>
          
        <ItemsControl ItemsSource="{Binding Signals}" >
          <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
              <Canvas />
            </ItemsPanelTemplate>
          </ItemsControl.ItemsPanel>
            
          <ItemsControl.ItemTemplate>
            <DataTemplate>
              <Ellipse Canvas.Left="{Binding SignalX}" Canvas.Top="{Binding SignalY}" Width="5" Height="5"/>
            </DataTemplate>
          </ItemsControl.ItemTemplate>
        </ItemsControl>
      </Grid>
    </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>

As a side note, I also advise against using accessible fields. Anything that can be a public field can be a property easily. Even if it’s just an auto-property, it will save you a lot of trouble down the road. Keep those fields private… always.

public int SignalX { get; }
public int SignalY { get; }
public Color ColorOn { get; } = Color.Green;
public Color ColorOff { get; } = Color.Red;
public string Name { get; }
public List<Signals> Signals { get; } = new();

8

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật