Welcome to the Xceed Community | Help
Community Search  
More Search Options

ContentTemplate on ColumnManagerCell does not work

Sort Posts: Previous Next
  •  08-29-2008, 7:53 AM Post no. 14649

    ContentTemplate on ColumnManagerCell does not work

    Hi,

     I am trying to replace the default appearance of the ColumnMangerCell by providing a ContentTemplate. The code looks like this:

     

    <Style TargetType="{x:Type xcdg:ColumnManagerCell}">

    <!--<EventSetter Event="MouseDown" Handler="Column_MouseDown" /> does not work why?-->

    <EventSetter Event="PreviewMouseDown" Handler="Column_MouseDown" />

    <Setter Property="ContextMenu" Value="{StaticResource cm}" />

    <Setter Property="ContentTemplate">

    <Setter.Value>

    <DataTemplate>

    <StackPanel Orientation="Horizontal">

    <TextBlock Text="+" Margin="0,0,3,0" />

    <ContentPresenter />

    </StackPanel>

    </DataTemplate>

    </Setter.Value>

    </Setter>

    </Style>

    The new appearance is never shown. Any ideas why?

     BR

    Carsten

  •  08-29-2008, 8:01 AM Post no. 14650 in reply to 14649

    Re: ContentTemplate on ColumnManagerCell does not work

    You can change the background of an item in the headers by setting its Background property to the desired color. However, you must keep the following in mind:

    <b>In some cases, property values defined in a style will not be applied to a target element. </b> 

    These include, but are not limited to: 
    - The element's template does not have a binding for the specific property. 
    - The element's template ignores the property value. 
    - The element's template explicitly provides a value for the property. 

    Refer to the <a href="http://doc.xcd/XceedWpfDataGrid/Headers%20and%20Footers.html">Headers and Footers</a> topic in the documentation for some examples.

    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  03-12-2009, 10:35 AM Post no. 19240 in reply to 14649

    Re: ContentTemplate on ColumnManagerCell does not work

    We had the same problem, here is a workaround:

    create a global ResourceDictionary with an associated CodeBehind file

    http://stackoverflow.com/questions/92100/is-it-possible-to-set-code-behind-a-resource-dictionary-in-wpf-for-event-handli

    //////////////////////////////////  XAML  ////////////////////////////////////////////////////////

    <!-- Template for a multiline ColumnHeader -->

    <DataTemplate x:Key="columnManagerContentTemplate">
            <TextBlock    Text="{Binding}"
                        TextWrapping="WrapWithOverflow"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Center" />
    </DataTemplate>

     <!-- Implicit style for a ColumnManagerCell -->

    <Style TargetType="{x:Type xcdg:ColumnManagerCell}">
            <EventSetter Event="Loaded" Handler="ColumnManagerCell_Loaded"/>
    </Style>

    //////////////////////////////////  CodeBehind //////////////////////////////////////////////////////// 

    private void ColumnManagerCell_Loaded(object sender, RoutedEventArgs e)
    {
        ColumnManagerCell columnManagerCell = sender as ColumnManagerCell;
        if (columnManagerCell != null)
        {
            if (columnManagerCell.ContentTemplate == null)
            {
                columnManagerCell.ContentTemplate = this["columnManagerContentTemplate"] as DataTemplate;
            }
        }
    }


View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.