Home Forums WPF controls Xceed DataGrid for WPF CellContentTemplate Binding

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25900 |

    Before I provided CellContentTemplate for one of my columns it was happy to display the integer Id. When I try to specify the CellContentTemplate I have a problem biding a property of my custom control to an actual value of that column

    here is the xaml

    <xcdg:Column FieldName=”RateModificationId” Title=”Rate Mod ID” Width=”150″ DisplayMemberBinding=”{Binding Path=RateModificationId}”> <xcdg:Column.CellContentTemplate>
    <DataTemplate>
    <m:ucRateModification ID=”{Binding Converter={z:DebugBinding}}”/>
    </DataTemplate>
    </xcdg:Column.CellContentTemplate>
    </xcdg:Column>

    in my DebugBinding converter
    public class DebugValueConverter : IValueConverter
    {
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
    System.Diagnostics.Debugger.Break();
    return Binding.DoNothing;
    }……

    value is always equal to an empty string

    What should I bind the ‘ID’ property of m:ucRateModification to?

    Thanx, Alex.

    Imported from legacy forums. Posted by Alex (had 6719 views)

    User (Old forums)
    Member
    Post count: 23064

    Xceed team, any ideas?

    Imported from legacy forums. Posted by Alex (had 983 views)

    User (Old forums)
    Member
    Post count: 23064

    use “{xcdg:CellContentBinding}” instead

    Imported from legacy forums. Posted by nat (had 799 views)

    User (Old forums)
    Member
    Post count: 23064

    Nope….
    Did not even hit my setter for ID property;

    public static DependencyProperty IDProperty = DependencyProperty.Register(“ID”, typeof(int?), typeof(ucRateModification));
    public int? ID
    {
    get { return (int?)((DependencyObject)this).GetValue(IDProperty); }
    set {
    ((DependencyObject)this).SetValue(IDProperty, value);
    SetDisplayValue();
    }
    }
    :@

    Imported from legacy forums. Posted by Alex (had 621 views)

    User (Old forums)
    Member
    Post count: 23064

    It won’t. Setter is not called for dependency object. You should register for value change in dependency property instead to get the notification.

    Imported from legacy forums. Posted by nat (had 655 views)

    User (Old forums)
    Member
    Post count: 23064

    OK,
    Made it much easier…

    <xcdg:Column FieldName=”RateModificationId” Title=”Rate Mod ID” Width=”150″ DisplayMemberBinding=”{Binding Path=RateModificationId}”>
    <xcdg:Column.CellContentTemplate>
    <DataTemplate>
    <TextBlock Text=”{xcdg:CellContentBinding}”/>
    <!–<m:ucRateModification ID=”{xcdg:CellContentBinding}”/>–>
    </DataTemplate>
    </xcdg:Column.CellContentTemplate>
    </xcdg:Column>

    TextBlock is still empty!!!

    HELP!!!

    Imported from legacy forums. Posted by Alex (had 728 views)

    User (Old forums)
    Member
    Post count: 23064

    Forgot to metion that I did try providing a PropertyChangedCallback for my DP… it still did not work. It never hit the breakpoint inside my callback delegate.

    Imported from legacy forums. Posted by Alex (had 657 views)

    User (Old forums)
    Member
    Post count: 23064

    It should be “ID”

    Imported from legacy forums. Posted by nat (had 1663 views)

    User (Old forums)
    Member
    Post count: 23064

    what should be ID?

    Not exactly sure what you are talking about…

    Imported from legacy forums. Posted by Alex (had 590 views)

    User (Old forums)
    Member
    Post count: 23064

    OK…. I got the answer.. the answer is that ID=”{Binding}”

    After examinning the visual tree of a grid I realized that the cell value is assigned to the datacontext of my user control.

    However my original solution did not work because I was expecting a setter to be called on my property instead of registering a property changed callback delegate.

    All clear now.

    Thanx.

    Imported from legacy forums. Posted by Alex (had 6878 views)

    User (Old forums)
    Member
    Post count: 23064

    Alex/nat,

    I’m seeing a similar problem. I have a custom control (specialization of ContentPresenter) that binds one of its own properties (a property called value that is implemented as a DependencyProperty) to its own ContentProperty. I’ve done the trick of adding a “identity” converter to the binding so that I can see values passed through and they’re always either null or empty string.

    This is all working towards a more generic solution to the problem giving the appearance of denormalizing data relations (the row to display contains a foreign key but you want to display the ‘text’ that gives a meaningful description to the foreign key) – more generic that what’s provided by the “Solid Foundation Sample” but right now I’d be happy to have my data templates binding correctly.

    [An interesting aside: I see the constructor of my KeyToValuePresenter called significantly more times than I have rows in the table. In fact, I get a recursion overflow error during layout because all of the input to the KeyToValuePresenter is either null or empty string as I said above].

    The code 

             private static readonly DependencyProperty KeyValueProperty =
                DependencyProperty.Register(“KeyValue”, typeof(object), typeof(KeyToValuePresenter));

             public object KeyValue
            {
                get
                {
                    return GetValue(KeyValueProperty);
                }
                set
                {
                    SetValue(KeyValueProperty, value);
                }
            }

            public KeyToValuePresenter()
            {
                 Binding contentBinding = new Binding();
                contentBinding.Mode = BindingMode.OneWay;
                contentBinding.Source = this;
                contentBinding.Path = new PropertyPath(KeyValueProperty);
                contentBinding.Converter = new IdentityConverter();

                this.SetBinding(KeyToValuePresenter.ContentProperty, contentBinding);
            }

    The XAML:

                     <xcdg:Column FieldName=”INSTRUMENTID”
                                 IsMainColumn=”False”
                                 Title=”Instrument”
                                 ReadOnly=”False”
                                 CellContentTemplate=”{StaticResource InstrumentIDToInstrumentDataTemplate}”>
                        <xcdg:Column.CellContentTemplate>
                            <DataTemplate>
                                <sp:KeyToValuePresenter
                                    KeyValue=”{Binding}”
                                    >
                                </sp:KeyToValuePresenter>
                            </DataTemplate>
                        </xcdg:Column.CellContentTemplate>

    Imported from legacy forums. Posted by Michael (had 1119 views)

    User (Old forums)
    Member
    Post count: 23064

    Been doing some more work on this and found that the binding to get data into the KeyValue property is working but from KeyValue to Content is “not working” – only ever has empty strings when binding in code. If I bind in XAML using 

    Content={Binding RelativeSource={x:Static RelativeSource.Self}, Path=KeyValue}

    then data flows from the “value of the column” –> KeyValue –>  Content and is displayed correctly.

    Anyone have any ideas why my binding in code is not working?

    Imported from legacy forums. Posted by Michael (had 2201 views)

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.