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

Bind a property with a criteria

1 Answer 41 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Trevor
Top achievements
Rank 1
Trevor asked on 29 Jul 2011, 05:42 PM
I have two questions.
First isn't neccesairly related to a context menu. How can bind the IsEnabled property to whether or not a selected item in a datagrid matches a criteria.  The criteria being a property from the datasource called Status value being between 15 and 40. I could run a check afterwards in the VB codebehind before actually executing something from the context menu, but I would like it to be displayed as greyed out for the user. I am using RIA services and binding to a domaindatasource.

Second is something I ran accross while trying to find a solution for #1, is whether you can bind the header values in the radcontextmenu to a datasource. I was just doing this to check the binding but it comes up as an empty entry in the context menu.

Here is a snippet of what I was working with.

<

 

 

telerik:RadGridView x:Name="ProjectGrid" ItemsSource="{Binding ElementName=ProjectData,Path=Data}" DataContext="{StaticResource ProjectTemplate}">
 <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu DataContext="{Binding ElementName=ProjectGrid,Path=SelectedItem}">
                    <telerik:RadContextMenu.Items>
                        <telerik:RadMenuItem Header="Collect $200 and Pass Go" IsEnabled=" "/>
                        <telerik:RadMenuItem Header="{Binding ElementName=ProjectGrid,Path=SelectedItem.First}"/>
                        <telerik:RadMenuItem Header="{Binding Status}"/>
                    </telerik:RadContextMenu.Items>
                </telerik:RadContextMenu>
 </telerik:RadContextMenu.ContextMenu>
</telerik:RadGridView>

1 Answer, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 03 Aug 2011, 02:59 PM
Hello,

You can use RowStyleSelector to achieve your goal. Please refer to our demos for more info.
As to the context menu you have to bind it like so:

<telerik:RadGridView Grid.Row="0" 
                            x:Name="clubsGrid"
                            ItemsSource="{Binding Clubs}"
                            AutoGenerateColumns="False"
                            RowDetailsTemplate="{StaticResource RowDetailsTemplate}"
                            Margin="5">
                               <telerik:RadContextMenu.ContextMenu>
                                   <telerik:RadContextMenu >
                                   <telerik:RadContextMenu.Items>
                       <telerik:RadMenuItem Header="{Binding Path=Menu.UIElement.SelectedItem.Name,  RelativeSource={RelativeSource Self}}" />
                                       <telerik:RadMenuItem Header="Menu Header"/>
                                       <telerik:RadMenuItem Header="Menu Item"/>
                                   </telerik:RadContextMenu.Items>
                               </telerik:RadContextMenu>
                           </telerik:RadContextMenu.ContextMenu>
                           <telerik:RadGridView.Columns>
                               <telerik:GridViewToggleRowDetailsColumn/>
                               <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
                               <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                           Header="Est." 
                                           DataFormatString="{}{0:yyyy}"/>
                               <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}" 
                                           Header="Stadium" 
                                           DataFormatString="{}{0:N0}"/>
                           </telerik:RadGridView.Columns>
                       </telerik:RadGridView>

Where the "Name" in the SelectedItem is the property of the object in the ViewModel to which the GridView is bound.
Attached I am sending you the sample project I used for reference.

Hope this helps.

All the best,
Konstantina
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
Tags
General Discussions
Asked by
Trevor
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Share this question
or