Hi there,
I am using a XamDataGrid, and have created a ControlTemplate that I am adding to the CellValuePresenter setters.
The grid has a Status column which is where I have used the ControlTemplate.
I have created a simple sample project that demonstrates the issue I am having, which is in the ControlTemplate there is an Ellipse and TextBlock.
You can see the grid here, and the text is not being bound to the TextBlock in the ControlTemplate:
https://ibb.co/ir3Duk
You can see the way the markup shows as expected when put in a simple window:
https://ibb.co/iTGcLQ
What I am doing wrong in the ControlTemplate and how can I bind the value for the TrainingPercent property?
Here is a link to the sample project to replicate the issue:https://www.dropbox.com/s/6ehrigkty9depqq/WPFTests.zip?dl=0
Thank you for your time,
Scott
I have solved this.
The all I had to do was change the ContentControl elements Content attribute to bind on the DataItem
<ContentControl Content="{Binding DataItem}">
and then update the TextBlock element Text attribute to bind on just the property name.
<TextBlock Text="{Binding Path=TrainingPercent}"
Hopefully this helps someone else ;-)
Regards,
Noriko,
Thanks for the response. The Control Template is located in the resource file and is as follows:
<Setter Property="Control.Template" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:igWPF="http://schemas.infragistics.com/xaml/wpf" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Setter.Value> <ControlTemplate TargetType="igWPF:CellValuePresenter"> <Grid> <Border BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{x:Null}" Name="MainBorder" /> <ContentControl Content="{Binding Status}"> <ContentControl.Resources> <DataTemplate x:Key="UnknownIcon"> <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid> <Ellipse Stroke="#FF787878" Fill="#FFA5A5A5" StrokeThickness="2.5" Height="50" Width="50" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> <TextBlock Text="{Binding Path=DataItem.TrainingPercent}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 0 0 5" /> </Grid> </Viewbox> </DataTemplate> <DataTemplate x:Key="UntrainedIcon"> <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid> <Ellipse Stroke="#FF787878" Fill="#FFA5A5A5" StrokeThickness="2.5" Height="50" Width="50" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> <TextBlock Text="{Binding Path=DataItem.TrainingPercent}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 0 0 5" /> </Grid> </Viewbox> </DataTemplate> <DataTemplate x:Key="TrainedIcon"> <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid> <Ellipse Stroke="#FFAE5A21" Fill="#FFED7D31" StrokeThickness="2.5" Height="50" Width="50" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> <TextBlock Text="{Binding Path=DataItem.TrainingPercent}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 0 0 5" /> </Grid> </Viewbox> </DataTemplate> <DataTemplate x:Key="TrainingIcon"> <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid> <Ellipse Stroke="#FFAE5A21" Fill="#FF8F5732" StrokeThickness="2.5" Height="50" Width="50" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> <TextBlock Text="{Binding Path=DataItem.TrainingPercent}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 0 0 5" /> </Grid> </Viewbox> </DataTemplate> <DataTemplate x:Key="RunningIcon"> <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid> <Ellipse Stroke="#FF507E32" Fill="#FF70AD47" StrokeThickness="2.5" Height="50" Width="50" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> <TextBlock Text="{Binding Path=DataItem.TrainingPercent}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 0 0 5" /> </Grid> </Viewbox> </DataTemplate> <DataTemplate x:Key="StoppedIcon"> <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid> <Ellipse Stroke="#FF860000" Fill="#FFC00000" StrokeThickness="2.5" Height="50" Width="50" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> <TextBlock Text="{Binding Path=DataItem.TrainingPercent}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 0 0 5" /> </Grid> </Viewbox> </DataTemplate> </ContentControl.Resources> <ContentControl.Style> <Style TargetType="ContentControl"> <Setter Property="ContentTemplate" Value="{StaticResource UnknownIcon}"/> <Style.Triggers> <DataTrigger Binding="{Binding Path=DataItem.Status}" Value="Unknown"> <Setter Property="ContentTemplate" Value="{StaticResource UnknownIcon}"/> </DataTrigger> <DataTrigger Binding="{Binding Path=DataItem.Status}" Value="Untrained"> <Setter Property="ContentTemplate" Value="{StaticResource UntrainedIcon}"/> </DataTrigger> <DataTrigger Binding="{Binding Path=DataItem.Status}" Value="Trained"> <Setter Property="ContentTemplate" Value="{StaticResource TrainedIcon}"/> </DataTrigger> <DataTrigger Binding="{Binding Path=DataItem.Status}" Value="Training"> <Setter Property="ContentTemplate" Value="{StaticResource TrainingIcon}"/> </DataTrigger> <DataTrigger Binding="{Binding Path=DataItem.Status}" Value="Running"> <Setter Property="ContentTemplate" Value="{StaticResource RunningIcon}"/> </DataTrigger> <DataTrigger Binding="{Binding Path=DataItem.Status}" Value="Stopped"> <Setter Property="ContentTemplate" Value="{StaticResource StoppedIcon}"/> </DataTrigger> </Style.Triggers> </Style> </ContentControl.Style> </ContentControl> </Grid> </ControlTemplate> </Setter.Value> </Setter>
Hello Scott Laughton,
Thank you for posting in our community.
I'm researching your inquiry and find out it needs more time to investigate.
I have created a private support case with an ID of CAS-186164-Z5H4Y7 for you and I will continue assisting you via this support case. In order to view it on our web site please follow these steps:
1) Log in with your account on our web site - https://es.infragistics.com
2) From the Support/Account menu item select View Account Info. This will lead you to My Keys & Downloads page - https://es.infragistics.com/my-account/keys-and-downloads
3) From the menu on the left side of the page select Support Activity - https://es.infragistics.com/my-account/support-activity
There you will find a list with all the active cases.
Please let me know if you have any additional questions regarding this matter.
Best Regards,
Noriko I.Developer Support EngineerInfragistics, Inc.