Attempting to use an sfSlider control inside of a grid cell, but I can't seem to make the binding work correctly. Does anyone have any ideas?
<datagrid:SfDataGrid x:DataType="vm:AddSchedulePopupViewModel"
ItemsSource="{Binding SelectedSchedule.ObservableSteps}"
SelectedRow="{Binding SelectedStep}"
AllowDeleting="True"
AllowEditing="True"
SelectionMode="Single"
SelectionUnit="Row"
RowHeight="90"
WidthRequest="1000"
AutoGenerateColumnsMode="None">
<datagrid:SfDataGrid.SortColumnDescriptions>
<datagrid:SortColumnDescription ColumnName="StepOrder"
SortDirection="Ascending" />
</datagrid:SfDataGrid.SortColumnDescriptions>
<datagrid:SfDataGrid.Columns>
<datagrid:DataGridTemplateColumn HeaderText="Target (C)" MappingName="TargetTemp"
Width="600">
<datagrid:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<sliders:SfSlider Minimum="100"
Maximum="1600"
StepSize="1"
Interval="1"
NumberFormat="#,##0"
ShowLabels="False"
Value="{Binding TargetTemp}">
<sliders:SfSlider.Tooltip>
<sliders:SliderTooltip ShowAlways="True"
Fill="Red"
FontSize="20"
FontAttributes="Bold"
TextColor="White" />
</sliders:SfSlider.Tooltip>
</sliders:SfSlider>
</DataTemplate>
</datagrid:DataGridTemplateColumn.CellTemplate>
</datagrid:DataGridTemplateColumn>
<datagrid:DataGridTemplateColumn HeaderText="DPM (C)" MappingName="RampRate"
Width="100">
<datagrid:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<sliders:SfSlider Minimum="0"
Maximum="150"
StepSize="1"
Interval="15"
NumberFormat="##0"
ShowLabels="False"
Value="{Binding RampRate}">
<sliders:SfSlider.Tooltip>
<sliders:SliderTooltip ShowAlways="True"
Fill="DarkBlue"
FontSize="20"
FontAttributes="Bold"
TextColor="White" />
</sliders:SfSlider.Tooltip>
</sliders:SfSlider>
</DataTemplate>
</datagrid:DataGridTemplateColumn.CellTemplate>
</datagrid:DataGridTemplateColumn>
<datagrid:DataGridTemplateColumn HeaderText="Hold Time (M)" MappingName="Duration"
Width="300">
<datagrid:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<sliders:SfSlider Minimum="0"
Maximum="300"
StepSize="1"
Interval="15"
NumberFormat="##0"
ShowLabels="False"
Value="{Binding Duration}">
<sliders:SfSlider.Tooltip>
<sliders:SliderTooltip ShowAlways="True"
Fill="DarkGreen"
FontSize="20"
FontAttributes="Bold"
TextColor="White" />
</sliders:SfSlider.Tooltip>
</sliders:SfSlider>
</DataTemplate>
</datagrid:DataGridTemplateColumn.CellTemplate>
</datagrid:DataGridTemplateColumn>
</datagrid:SfDataGrid.Columns>
</datagrid:SfDataGrid>
We have reviewed your reported query and the provided code snippet. It appears that while you have correctly set the x:DataType for the SfDataGrid's BindingContext (i.e., the ViewModel), the x:DataType was not specified for the DataTemplate used in the CellTemplate of the DataGridTemplateColumn. This is the reason the property bindings inside the CellTemplate were not working as expected.
<datagrid:SfDataGrid> <datagrid:SfDataGrid.Columns> <datagrid:DataGridTemplateColumn> <datagrid:DataGridTemplateColumn.CellTemplate> <DataTemplate x:DataType="vm:ScheduleStep"> <sliders:SfSlider Minimum="100" Maximum="1600" StepSize="1" Interval="1" NumberFormat="#,##0" ShowLabels="False" Value="{Binding TargetTemp}"> <sliders:SfSlider.Tooltip> <sliders:SliderTooltip ShowAlways="True" Fill="Red" FontSize="20" FontAttributes="Bold" TextColor="White" /> </sliders:SfSlider.Tooltip> </sliders:SfSlider> </DataTemplate> </datagrid:DataGridTemplateColumn.CellTemplate> </datagrid:DataGridTemplateColumn> </datagrid:SfDataGrid.Columns> </datagrid:SfDataGrid> |
Riyas Hameed M
Attachment: DataGridMAUI_(3)_1b12512b.zip
Thank you, the solution basically worked with the exception that I had to define the Step Model from the model namespace. Thank you for your help
Hi David Kendall,
We are pleased to hear that the provided solution is working well for you. Please feel free to reach out if you require any further assistance.
Regards,
Riyas Hameed M
- 3 Replies
- 2 Participants
-
DK David Kendall
- May 13, 2025 08:34 PM UTC
- May 15, 2025 09:09 AM UTC