1

.NET 4, Caliburn Micro. I need add textBox, comoboBox and some another controls to datagrid headers and bind property from view model class on these controls.

So I try use HeaderTemplate:

XAML:

<DataGrid ItemsSource="{Binding Calls}"
              AutoGenerateColumns="False">
    <DataGrid.Columns>

        <DataGridTextColumn  IsReadOnly="True"
                             CellStyle="{StaticResource CellStyle}"
                             Binding="{Binding Path=Number}">

            <DataGridTextColumn.HeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <TextBlock Text="Cell phone No"/>
                        <TextBox Width="120" 
                                 FontSize="14" 
                                 VerticalAlignment="Center"
                                 BorderThickness="1"
                                 Text="{Binding Path=NumberFilterValue,
                                                Mode=OneWayToSource,
                                                UpdateSourceTrigger=PropertyChanged}"/>
                    </StackPanel>
                </DataTemplate>
            </DataGridTextColumn.HeaderTemplate>
        </DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

In header I have textBox control and I try bind property NumberFilterValue from view model class.

View model class:

    public string NumberFilterValue
    {
        get { return _numberFilterValue; }
        set
        {
            _numberFilterValue = value;
            NotifyOfPropertyChange(() => NumberFilterValue);
            FilterCalls();
        }
    }

Problem is that this binding does not works. Property NumberFilterValue is still empty.

What is root of this problem and how can solve it? Thank you for cooperation.

  • Are you expecting your ViewModel property to update as you enter text, or when you leave the current text field? – EtherDragon Aug 01 '11 at 19:18

1 Answers1

0

If you are sure you meant OneWayToSource and not OneWay you should read this: OneWayToSource Binding seems broken in .NET 4.0

Community
  • 1
  • 1
anivas
  • 6,437
  • 6
  • 37
  • 45