Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
CellValuePresenter control template that acceses other values of bound data item
posted
I would like to make a cell value presenter control template that displays an icon depending on one value of the bound data item and some text from another property of the bound data item. I know to bind to the content of the field associated with the cellvaluepresenter I can use...

<TextBlock Width="Auto" Height="Auto" Text="{TemplateBinding Content}" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="5,0,0,0" VerticalAlignment="Center" Foreground="#FF000000" x:Name="textBlock"/>

How can I bind to another field/property for the data item? Should I bind to something on the TemplatedParent or is this just impossible?

Thanks! I've provided my full control template below....

 

<Style x:Key="UnitTypeFieldCellImages" TargetType="{x:Type igDP:CellValuePresenter}">

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">

<StackPanel x:Name="stackPanel" Orientation="Horizontal">

<Grid Margin="5,0,0,0" x:Name="grid" Width="32" Height="32">

<Grid Width="32" Height="32" x:Name="policecarimage" Visibility="Visible" HorizontalAlignment="Left" VerticalAlignment="Top">

<!--<Image Source="images/policecar_32.png" Height="32" Width="32" />-->

<Image Source="{StaticResource CopCarIcon}" Height="32" Width="32" />

</Grid>

<Image x:Name="firetruckimage" Source="{StaticResource FireTruckIcon}" Height="32" Width="32" Visibility="Hidden" />

</Grid>

<TextBlock Width="Auto" Height="Auto" Text="{TemplateBinding Content}" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="5,0,0,0" VerticalAlignment="Center" Foreground="#FF000000" x:Name="textBlock"/>

</StackPanel>

<ControlTemplate.Triggers>

<Trigger Property="Content" Value="FD">

<Setter Property="Visibility" TargetName="policecarimage" Value="Hidden"/>

<Setter Property="Visibility" TargetName="firetruckimage" Value="Visible"/>

</Trigger>

</ControlTemplate.Triggers>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

Parents
  • 8576
    Offline posted
    Hi -
     
    Since the DataContext of the CellValuePresenter is set to the DataRecord, you can use a standard binding where the Path parameter is set to the name of the Field/Property you want to bind to off the DataItem property of the DataRecord. (the DataItem property returns the underlying data for the DataRecord)
     
    {Binding Path=DataItem.MyFieldName}

    Joe

     

    "meverett99" wrote in message news:21876@forums.infragistics.com...
    I would like to make a cell value presenter control template that displays an icon depending on one value of the bound data item and some text from another property of the bound data item. I know to bind to the content of the field associated with the cellvaluepresenter I can use...

    <TextBlock Width="Auto" Height="Auto" Text="{TemplateBinding Content}" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="5,0,0,0" VerticalAlignment="Center" Foreground="#FF000000" x:Name="textBlock"/>

    How can I bind to another field/property for the data item? Should I bind to something on the TemplatedParent or is this just impossible?

    Thanks! I've provided my full control template below....

     

    <Style x:Key="UnitTypeFieldCellImages" TargetType="{x:Type igDP:CellValuePresenter}">

    <Setter Property="Template">

    <Setter.Value>

    <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">

    <StackPanel x:Name="stackPanel" Orientation="Horizontal">

    <Grid Margin="5,0,0,0" x:Name="grid" Width="32" Height="32">

    <Grid Width="32" Height="32" x:Name="policecarimage" Visibility="Visible" HorizontalAlignment="Left" VerticalAlignment="Top">

    <!--<Image Source="images/policecar_32.png" Height="32" Width="32" />-->

    <Image Source="{StaticResource CopCarIcon}" Height="32" Width="32" />

    </Grid>

    <Image x:Name="firetruckimage" Source="{StaticResource FireTruckIcon}" Height="32" Width="32" Visibility="Hidden" />

    </Grid>

    <TextBlock Width="Auto" Height="Auto" Text="{TemplateBinding Content}" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="5,0,0,0" VerticalAlignment="Center" Foreground="#FF000000" x:Name="textBlock"/>

    </StackPanel>

    <ControlTemplate.Triggers>

    <Trigger Property="Content" Value="FD">

    <Setter Property="Visibility" TargetName="policecarimage" Value="Hidden"/>

    <Setter Property="Visibility" TargetName="firetruckimage" Value="Visible"/>

    </Trigger>

    </ControlTemplate.Triggers>

    </ControlTemplate>

    </Setter.Value>

    </Setter>

    </Style>



    http://forums.infragistics.com/forums/p/4617/21876.aspx#21876

Reply Children
No Data