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
170
Cannot bind using a DataTemplate in the XamDataPresenter
posted

I would like to know how to bind an object to a field in the XamDataPresenter using a DataTemplate.  It seems to be using the DataTemplate correctly, but I do not know how to retrieve the data I need, which in the example below is the “FillColor” property.

 

<igDP:XamDataPresenter.Resources>

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

    <Setter Property="ContentTemplate" Value="{StaticResource LightboardStatusTemplate}" />

  </Style>

</igDP:XamDataPresenter.Resources>

<igDP:XamDataPresenter.FieldLayouts>

  <igDP:FieldLayout>

    <igDP:FieldLayout.Fields>

     <igDP:Field Name="STATUS" Label="Lightboard">

      <igDP:Field.Settings>

        <igDP:FieldSettings CellWidth="70" LabelWidth="70" AllowEdit="False" CellValuePresenterStyle="{StaticResource Status}">

        </igDP:FieldSettings>

       </igDP:Field.Settings>

      </igDP:Field></igDP:FieldLayout.Fields>

   </igDP:FieldLayout>

</igDP:XamDataPresenter.FieldLayouts>

 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

                    xmlns:DRAMSClient="clr-namespace:Rades">

    <DataTemplate x:Key="LightboardStatusTemplate" DataType="{x:Type DRAMSClient:LightboardStatus}">

        <Label Content="{Binding Path=FillColor}" />

    </DataTemplate>

</ResourceDictionary>

    public class LightboardStatus

    {

        private string _FillColor;

        public string FillColor {

            get

            {

                return "#" + _FillColor;

            }

            set

            {

                _FillColor = value;

            }

        }

        public string BorderColor { get; set; }

    }

 

 

 

 


 

  • 170
    Verified Answer
    posted

    Nevermind.  This was my fault.  I realized that when I added a column to a DataRow, I did not set the column type to typeof(LightboardStatus).  This made it so that when the LightboardStatus object was set as the value of a cell of the new column, it was converted to its string representation.