i have the following problem.
if i use an image for a datagrid header i get an error while toggling visibility.
<DataGridTextColumn Header="{StaticResource Image_Link}" IsReadOnly="True">
Error: Bei dem angegebenen Element handelt es sich bereits um das logische untergeordnete Element eines anderen Elements.
the only workaround i found so far is to create a ControlTemplate with the specific image foreach of my imageheadercolumns.
is this datagrid behaviour a bug?
EDIT: Error translated by google: The specified element is already the logical child of another element.
EDIT: Sample
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Button Content="Toggle" Click="Button_Click" Height="20" Width="40" HorizontalAlignment="Left"/>
<DataGrid Width="200">
<DataGrid.Columns>
<DataGridTextColumn x:Name="colImage" Header="{StaticResource AnyImage}">
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
ResourceDictionary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Image x:Key="AnyImage" Source="Home.png" x:Shared="false"/>
</ResourceDictionary>
Button.Click:
private void Button_Click(object sender, RoutedEventArgs e)
{
this.colImage.Visibility = this.colImage.Visibility == Visibility.Visible
? Visibility.Collapsed
: Visibility.Visible;
}
**EDIT: Deleted the previous answer which wasn't relevant**
You will need to put the image in headertemplate of column. working sample code
I'm not sure what's causing this, but you could try to explicitly create the
Image
control to display the image: