Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
215
Odd Command Binding (Virtualization?) Problem
posted

 Hi All,

I have an odd command binding problem going on that I can't seem to iron out.  I have a custom complex object that is stored in an ObservableCollection and bound to the xamDataGrid as part of a ViewModel.  On the ViewModel I have a Composite Application LIbrary (Prism) command.  All is working as expected apart from the command.

One of the properties of the complex object is a UserControl that contains a button that plays an audio file.  This button is used in an UnboundField in the xamDatagrid the field is defined like:

            Field idPlayButton = new Field();
            idPlayButton.DataType = typeof(Button);
            idPlayButton.Name = "PlayButton";
            idPlayButton.Label = "Play Sample";
            FieldList.Add(idPlayButton);

 

The command on this button in the UserControl is:

Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=DataContext.PlayCommand}"

All of this is working as expect for the records in the xamDataGrid that are rendered in the UI.  The buttons in each record play the relevant audio file, as soon as you scroll down to view further records it appears that the command hasn't been bound to these buttons.  I have altered the screen size to show more and less records and I see the same behaviour each time.  The records you can see at startup play the audio files whilst those not rendered at startup don't ...

Does anyone have anyideas as to what is going on here?  The only way I've gotten each button to correctly bind to the command is to set:

RecordContainerGenerationMode="PreLoad"

But this means my app ends up using over a gig of RAM!!  And it makes the app and the xamDataGrid incredibly sluggish.  Any input or ideas would be really appreciated.

Thanks,

James. 

Parents
  • 3627
    posted

    I wonder if this is related to a problem I have observed.

    I have a grid where each row has a button that's bound to a command. The buttons' visibility property is set to the command's CanExecute, so they won't even appear if they can't be executed. If I resize my form, any newly exposed rows will not have buttons. I have to scroll the grid to force it to re-evaluate the bindings and get the buttons to appear.

Reply Children