locked
List-Detail strange TextBox binding behaviour

    Question

  • Hello,

    I use a page with List-Detail parts linked through SelectedItem. On the Detail panel there are TextBoxes and CheckBoxes bound to the selected list item Model properties with TwoWays method.
    On loading this page weirdly TextBox bound Model properties Setters are called, but not CheckBox bound property setters, which is good.
    This is annoying as it sets Modified flag on the bound Model.

    Is it corrent behaviour of the TextBoxes?

    Thanks in advance for any clarifications.

    Tuesday, March 18, 2014 8:56 PM

All replies

  • I'm not following the scenario. Can you please provide more detail?

    If you can upload a minimal sample demonstrating the problem to your OneDrive that would be very helpful.

    --Rob

    Wednesday, March 19, 2014 2:57 AM
    Owner
  • Hello Rob,

    Thank you for your reply.

    I put a sample to illustrate the problem.

    It's a standard VS template SplitApp, on the second page "SplitPage" there is a List of data (left part) and the Detail of the selected list Item to the right bound between through the "SelectedItem".

    Xaml:

    DataContext="{Binding SelectedItem, ElementName=itemListView}"

    Detail exposes Title, Subtitle properties as TextBoxes, IsValidated property as Checkbox with Mode=TwoWay and Content property as TextBlock.

    <TextBox x:Name="itemTitle" Margin="0,-10,0,0" Text="{Binding Title, Mode=TwoWay}" />
    <TextBox x:Name="itemSubtitle" Margin="0,0,0,20" Text="{Binding Subtitle, Mode=TwoWay}" />
    <CheckBox x:Name="itemValidated" Content="Validated" Margin="0,0,0,20" IsChecked="{Binding IsValidated, Mode=TwoWay}" />

    When this page is opened all the getters of all properties (Title, Subtitle, IsValidated) are called - which is correct, but at the same time the setters of Title and Subtitle properties are called (!!!?? - why?), but not of the IsValidated set to Checkbox - this is correct.
    Why TextBox gets and then sets the bound property value?

    My problem is that if setter is called it marks the Model as Modified, but in reality it was not!!!

    In the code above I have not added this marking, but it would be something like this:

    public string Title {

    get...

    set { _title = value; Modified = true; OnPropertyChanged(); } }

    The behavior of the bound Checkbox is, in my view, normal.

    Thank you in advance,
    Alexandre

    Wednesday, March 19, 2014 9:18 AM
  • Here is the sample SplitApp:

    https:SLASH SLASH onedrive DOT live DOT com/?gologin=1&mkt=en-US#cid=256AB29D099BCBD1&id=256AB29D099BCBD1%21115

    strangly I can add the address only in this awkward way!!!

    SLASH and DOT  - to replace

    Wednesday, March 19, 2014 9:27 AM