Question: Binding Filter to Property of an Custom Control #115
-
I have created a CustomControl called “NumberTextBox” that can be used to bind the “Value” directly to Integer or Double properties within my ViewModel. This CustomControl is derived from the WPF TextBox and also has the property “Text” that gets set when “Value” is set. Within DataGrids, I am using a “DataGridTemplateColumn” to display the “gui:NumberTextBox”. My question is: how can I set a DataGrid filter to a property of my custom control, in this case to “gui:NumberTextBox:Text”, within a “DataGridTemplateColumn”? Is that possible? Note: dgx is the namespace “xmlns:dgx=“urn:tom-englert.de/DataGridExtensions”” <DataGrid
Width="400"
Height="200"
dgx:DataGridFilter.IsAutoFilterEnabled="True"
AutoGenerateColumns="False"
ItemsSource="{Binding ExampleData}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Nr">
<!-- TODO: Here i´d like to set datagrid filter to property "gui:NumberTextBox.Text" -->
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<gui:NumberTextBox
IsIntegerOnly="True"
Style="{StaticResource DataGridNumberTextColumnStyle}"
Value="{Binding Nr, UpdateSourceTrigger=PropertyChanged, Delay=300, ValidatesOnNotifyDataErrors=true}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<!-- WICHTIG : "CellEditingTemplate" muss angegeben werden, sonst würde Editieren nicht funktionieren auch die Angabe von UpdateSourceTrigger ist wichtig! -->
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<gui:NumberTextBox
IsIntegerOnly="True"
Style="{StaticResource DataGridNumberTextColumnStyle}"
Value="{Binding Nr, UpdateSourceTrigger=PropertyChanged, Delay=300, ValidatesOnNotifyDataErrors=true}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
|
Beta Was this translation helpful? Give feedback.
Answered by
tom-englert
Sep 9, 2024
Replies: 1 comment 1 reply
Answer selected by
MakeGywer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/dotnet/DataGridExtensions/blob/master/Documentation/topics/Filtering.md#filtering-and-sorting-a-template-column