I have a icon(rectangle) in my XAML which has a contextmenu bound to it. What I want to achive is for the icon and the contextmenu to bind some values togheter in a string, which is later going to be used in another method.
To give a more vivid example, I have four icons, the represent four physical object. In the contextmenu I have a connectionstring to all four objects. The information I need from the action of pressing the icons and the connectionstring via the contextmenu builds the final connectionstring, ie. from object to object. To make it a little bit more complex, both the connectionstrings and the icons are dynamically handed via an API.
The problem I'm having is that I can't find a good way bind my icon to the value it is representing, when I'm using the contextmenu, since the values of the contextmenu are bound to one list and the other value is bound to a string. I wouldn't like to have a x:Name approach that is static, since it wouldn't make an oppertunity to also later create the icons dynamically, this approach I did try, as you can see in the code and was a success, but as I said, it would be prefeered to have a more dynamic approach.
<Rectangle Tag="{Binding TrackID}" x:Name="Test" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="23" Margin="122,117,0,0" Stroke="Black" VerticalAlignment="Top" Width="28">
<Rectangle.ContextMenu>
<ContextMenu ItemsSource="{Binding tracksMenuList1}" ContextMenuClosing="ContextMenu_ContextMenuClosing" MenuItem.Click="ContextMenu_Click">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header" Value="{Binding Tracks}"/>
<Setter Property="Uid" Value="{Binding id}"/>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</Rectangle.ContextMenu>
</Rectangle>