Bind the Ribbon:Button Tag Property to the ThemedDataGrid SelectedIndex Property

Ribbon for WPF Forum

Posted 4 months ago by Peter Treier
Version: 19.1.0685
Avatar

Good Afternoon,

I try to Bind the Tag Property of a ThemedDataGrid ContextMenu Button to the Grids SelectedIndex...

All I get is : Error: 4 : Cannot find source for binding with reference 'ElementName=processDataGrid'. BindingExpression:Path=SelectedIndex; DataItem=null; target element is 'Button' (Name=''); target property is 'Tag' (type 'Object')

The Goal: My Command should receive the SelectedIndex or better the SelectedItem as a Paramter.

Here is my approach

<datagrid:ThemedDataGrid x:Name="processDataGrid" AutoGenerateColumns="False" ItemsSource="{Binding ProcessList}" SelectionMode="Single">

	<datagrid:ThemedDataGrid.ContextMenu>
		<ribbon:ContextMenu>
			<StackPanel>
				<ribbon:Menu>
					<ribbon:Separator Label="Processes" />
					<ribbon:Button Label="Watch this" ImageSourceSmall="Ressources/Images/16/process-browse.png"
								   Command="{Binding AddWatchCommand}" 
                                                                   Tag="{Binding SelectedIndex, ElementName=processDataGrid}"/>
				</ribbon:Menu>
			</StackPanel>
		</ribbon:ContextMenu>
	</datagrid:ThemedDataGrid.ContextMenu>

	<datagrid:ThemedDataGrid.Columns>
		<DataGridTextColumn x:Name="ProcessName" Binding="{Binding ProcessName}" Header="Process Name" Width="*" />
		<DataGridTextColumn x:Name="Id" Binding="{Binding Id}" Header="Process Id" Width="75" />
		<DataGridTextColumn x:Name="Responding"
							Binding="{Binding Responding, Converter={StaticResource ProcessRespondingToTextConverter}}"
							Header="Responding" Width="100" />
		<DataGridTextColumn x:Name="TotalProcessorTime" Binding="{Binding TotalProcessorTime}"
							Header="Total Processor Time" Width="150" />
		<DataGridTextColumn x:Name="WorkingSet64"
							Binding="{Binding WorkingSet64, Converter={StaticResource FileSizeConverter}}"
							Header="Working-Set 64" Width="150" />
	</datagrid:ThemedDataGrid.Columns>

</datagrid:ThemedDataGrid>

Comments (5)

Posted 4 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Peter,

ContextMenus in WPF don't always resolve names the same way since they are out of the normal visual tree.  What happens if you change that binding to "{Binding Source={x:Reference processDataGrid}, Path=SelectedIndex}"?  Sometimes using x:Reference works around "cannot find source" binding errors.


Actipro Software Support

Posted 4 months ago by Peter Treier
Avatar

Looks not so good :-(

XamlObjectWriterException: Cannot call MarkupExtension.ProvideValue because of a cyclical dependency. Properties inside a MarkupExtension cannot reference objects that reference the result of the MarkupExtension. The affected MarkupExtensions are:
'System.Windows.Data.Binding' Line number '148' and line position '63'.

Posted 4 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Peter,

What if you used a simpler native WPF ContextMenu instead?  Does that work?


Actipro Software Support

Posted 4 months ago by Peter Treier
Avatar

I'm working on another project this week.
Will test a simpler control next week - can we leave the thread open?

Posted 4 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Sure, please get back to us after testing that.  Thanks!


Actipro Software Support

The latest build of this product (v2020.1.0) was released 17 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.