Bind a property with a criteria

2 posts, 0 answers
  1. Trevor
    Trevor avatar
    13 posts
    Member since:
    Jun 2011

    Posted 29 Jul 2011 Link to this post

    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>

  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 03 Aug 2011 Link to this post

    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 >>
Back to Top