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

Binding to custom appointment properties

3 Answers 220 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 20 Oct 2011, 11:48 AM
Hi,

I've created a custom appointment just like this tutorial demonstrates.

Everything works fine, but now I'm trying to apply a style trigger to an appointmentiotemcontenttemplate:

        <DataTemplate x:Key="AppointmentItemContentTemplate">
            <Grid>
                <Border>
                    <Border.Style>
                        <Style>
                            <Style.Triggers>
                               <DataTrigger Binding="{Binding ProductCategory}" Value="Building">
                                    <Setter Property="Border.Background" Value="CornflowerBlue"></Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Border.Style>
                    <Grid>
                        <TextBlock Margin="8,2" HorizontalAlignment="Stretch" TextWrapping="Wrap" Text="{Binding Subject}" Grid.Column="1" />
                        <TextBlock Margin="8,2" HorizontalAlignment="Stretch" TextWrapping="Wrap" Text="{Binding ProductCategory}" Grid.Column="1" />
                    </Grid>
                </Border>
            </Grid>
        </DataTemplate>


In two instances here I'm trying to use the ProductCategory property, and it won't work. If I were to change the trigger to use the 'Subject' property of the appointments I am dragging (from a listbox I should add) onto the ScheduleView it works without a problem. Likewise, the textblock that attempts to display the ProductCategory does not work, whereas the 'Subject' does. It seems that any additional fields I have added to the Job.cs (custom appointment) are not accessible!? The syntax (private/get/set) is exactly the same as the tutorial so I can't understand it?

Thanks a LOT for any help in advance!

3 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 20 Oct 2011, 02:40 PM
I've lost a day on this, it's really pissin me off, if anyone can be arsed replying and providing any input whatsoever I'll be very grateful.
0
Yana
Telerik team
answered on 25 Oct 2011, 12:21 PM
Hi Daniel,

You should bind the custom property like this:

<TextBlock Margin="8,2" HorizontalAlignment="Stretch" TextWrapping="Wrap" Text="{Binding Appointment.ProductCategory}" Grid.Row="1" />

I've also attached a sample project for a reference.

Greetings,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Philipp
Top achievements
Rank 1
answered on 02 Nov 2011, 10:12 PM
I just stumbled over the same issue, so some context for the next guy/gal who searches for those terms: Apparently, the control creates proxy objects (AppointmentProxy) which are the data context of the data template. Accordingly, if you startup VS in debug mode, you'll see something like this in the Debug output:

BindingExpression path error: 'Foo' property not found on 'object' ''AppointmentItemProxy' (HashCode=53160041)'. BindingExpression:Path=Foo.Bar

With regards to the API, the proxy as the DataContext is probably bad practice, as it feels unfamiliar and makes development (especially in Blend) harder than it should be.
Tags
ScheduleView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Yana
Telerik team
Philipp
Top achievements
Rank 1
Share this question
or