I am making a real estate management program and on the main page I have all of the properties listed something like this in a WrapPanel:

Main Panel with Properties

Now, even though each of the properties is exactly the same, that is only for demonstration and testing with multiple properties. Each of the properties is a different Property object inside of an ObservableCollection Property (sorry for the confusion of names) as shown by my c# code below:

public ObservableCollection<Property> Properties { get; set; }

// ...

Property defaultProperty = new Property(/*Lots of Stuff*/);
properties.Add(defaultProperty);
properties.Add(defaultProperty);
properties.Add(defaultProperty);
properties.Add(defaultProperty);
properties.Add(defaultProperty);
Properties = properties;

These Properties (part of the Properties property (sorry again)) are then shown through an itemscontrol which is shown below:

<ItemsControl x:Name="wPanel" ItemsSource="{Binding Properties}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel x:Name="PropertyPanel" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Border  Margin="5,5,5,5" BorderBrush="Red"  BorderThickness="1" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Grid MinWidth="350" MouseLeftButtonUp="Grid_MouseLeftButtonUp">
                    // Column and Row Definitions
                    // ...
                    // Three other corners of the grid
                    <StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Bottom">
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5,5,5,0" MouseLeftButtonDown="IssuesPanel_MouseLeftButtonDown" > // <-- This is the part I'm trying to get to work
                            <TextBlock Text="{Binding IssuesNum}" VerticalAlignment="Center"/>
                            <TextBlock Text=" Issues " VerticalAlignment="Center"/>
                            <Image VerticalAlignment="Center">
                                <Image.Source>
                                    <BitmapImage UriSource="/VentureVisions;component/warning.png" DecodePixelWidth="18" />
                                </Image.Source>
                            </Image>
                        </StackPanel>
                   </StackPanel>
                </Grid>
            </Border>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

I took out the parts that didn't matter to this. I'm trying to open up a window about the issues of the property when the user clicks on the issues panel in the bottom right. I've got an event set up, but I need to be able to get the Property object to get the Issues collection from it to display in the window. I hope this makes sense. Comment if now. But how do I know how to reference the specific Property that the user is interacting with after the button click? Thank you.

有帮助吗?

解决方案

From what it looks like this is answered using several different flavours, refer to the following topics:

  1. Binding to CurrentItem in a ItemsControl
  2. How to highlight selected item in ItemsControl?

Hopefully those help.

To further aid you if you are using any level of data binding then you can simply bind the "issues" image interaction to a command on the "viewmodel", in your instance the viewmodel will be the Property object.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top