This is a migrated thread and some comments may be shown as answers.

Behaviors not working

6 Answers 207 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dirk
Top achievements
Rank 1
Iron
Dirk asked on 20 Jan 2014, 09:15 PM
I'm trying to use behaviors to get updates of a textbox after losing the focus.
But the behaviors are not working.
I'm using behaviors to have the event directly on the viewmodel of the view and not in the nested viewmodel of the grid.
This is the reason why I'm using the binding 
Path=DataContext.TitleUpdateCommand
Is this a bug?

<grid:DataGridTemplateColumn Header=
"Resource Name (UID)" CanUserFilter="False" Width="400">
    <grid:DataGridTemplateColumn.CellContentTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Title}" MaxWidth="400" FontFamily="Segoe UI, Verdana">
                <interactivity:Interaction.Behaviors>
                    <core:EventTriggerBehavior EventName="LostFocus">
                        <helper:InvokeCommand Command="{Binding Path=DataContext.TitleUpdateCommand, ElementName=Self}" />
                    </core:EventTriggerBehavior>
                </interactivity:Interaction.Behaviors>
            </TextBox>
        </DataTemplate>
    </grid:DataGridTemplateColumn.CellContentTemplate>
</grid:DataGridTemplateColumn>

6 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 22 Jan 2014, 01:45 PM
Hi Dirk,

Thank you for cooperation.

After some research here is what I have found: Generally, the Ui virtualization of the RadDataGrid calls the DataTemplate.LoadContent(..) method for templated columns and adds the content to the visual tree, but it seems that something clears the bindings when they are bound to the DataContext of another element. It may be some WinRT framework quirk, but at this point I am not sure what is the reason that causes this behavior.
As a workaround, if you define the source of the binding in the resources of the App or in the Page's resources, the binding will work properly.

Let me know should you have any questions or suggestions.


Regards,
Ivaylo Gergov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dirk
Top achievements
Rank 1
Iron
answered on 22 Jan 2014, 02:25 PM
Hi Ivaylo
thank you for your answer.
In my support ticket I've attached an example project.
Is it possible that you implement your workaround there.
I've still tried to define the source of the binding in the resource of of the view - but without any success.

If it doesn't work I will have to implement my own DataGrid control based on a ItemsControl where this kind of binding is working correctly.

Thanks
Dirk

0
Ivaylo Gergov
Telerik team
answered on 23 Jan 2014, 02:49 PM
Hi,

Unfortunatelly, the workaround requires that the viewmodel is defined in XAML. This seems to be inapplicable in prism/unity scenario like this. The only solution should be to consider an alternative viewmodel instantiation.

Sorry for any inconvenience caused. Let me know if you need further assistance.


Regards,
Ivaylo Gergov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dirk
Top achievements
Rank 1
Iron
answered on 23 Jan 2014, 09:43 PM

Hi Ivaylo,


this is really sad.

As a subscriber of the DevCraft Ultimate Edition I've always promoted Telerik controls because they have supported all the time Prism and MVVM bindings better that other 3rd Party control vendors.

I've used them in Silverlight and WPF projects.

Now with Windows 8 you break this rule..



I'll check if I build up my own simple datagrid control.



Regards

Dirk



0
Ivaylo Gergov
Telerik team
answered on 24 Jan 2014, 04:40 PM
Hello Dirk,

We feel your pain on this one but just wanted to clarify that supporting Prism and the MVVM paradigm as a whole has always been an important goal in our Windows 8 control development and we are by no means abandoning this policy now.

As part of the suite, RadDataGrid also provides support for the MVVM paradigm but your specific scenario hits an issue with the WinRT DataTemplate.LoadContent(...) method call for templated columns unexpectedly clearing the bindings as described in our first reply. We strongly believe that the problem is within the WinRT framework itself as similar issue existed in Silverlight 4 and was fixed in Silverlight 5. Basically, WinRT is not mature yet and currently can be thought to have the functionality (and problems) of something along the feature set of earlier Silverlight versions.

We understand that knowing that a problem is within the framework itself, and not in RadDataGrid does not solve your case, so we put a lot of effort in finding a proper workaround to remedy the situation. Unfortunately, the only available solution (setting the binding source declaratively in XAML) is indeed not Prism-friendly and cannot be applied without further modifications to your project.


Regards,
Ivaylo Gergov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dirk
Top achievements
Rank 1
Iron
answered on 25 Jan 2014, 02:54 PM
Hi Ivaylo,
at least i know a lot of the problems we still have with WinRT.
But why do developer use third party controls?
Because they want to have less work. Microsoft itself prefere ugly code behind programming. Verdors like Telerik helps to do better and faster development by using modern principles of programming.
As I mentioned I like Telerik controls. They are well designed and support Prism and MVVM. So they can be used in clean coded applications. (Respecting SoC, SRP, DI, etc.)
But if you only support MVVM in Windows Store apps in an 'ugly' way like declarative in the XAML then your controls still seems to look nice for the customers but not for the clean code developer.
At least I've tried 2 or 3 days to find the problem with the bindings of the RadGridControl.
Now (for the first step) I have build up my own 'simple' editable data grid with an ItemsControl with 100% MVVM bindings (also via DataContext... binding) in less than 2 hours.

Regards
Dirk
Tags
Grid for XAML
Asked by
Dirk
Top achievements
Rank 1
Iron
Answers by
Ivaylo Gergov
Telerik team
Dirk
Top achievements
Rank 1
Iron
Share this question
or