How do I implement a Close button

4 posts, 0 answers
  1. Denis Vuyka
    Denis Vuyka avatar
    39 posts
    Member since:
    Oct 2009

    Posted 30 Dec 2009 Link to this post

    Hello, can you give me any idea how the "Close" button can be implemented within the header of the item. We need removing items as well adding them ;)

    Regards
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 30 Dec 2009 Link to this post

    Hello Denis Vuyka,

    Here is a sample code:
    XAML:
    <Grid x:Name="LayoutRoot">
            <Grid.Resources>
                <DataTemplate x:Key="TileViewItemHeaderTemplate">
                    <StackPanel Orientation="Horizontal">
                        <Button Click="Button_Click_1" VerticalAlignment="Center" Content="X"></Button>
                        <TextBlock Text="{Binding}" Margin="5" VerticalAlignment="Center" />
                    </StackPanel>
                </DataTemplate>
            </Grid.Resources>
              
                <telerikNavigation:RadTileView x:Name="RadTileView1">
                    <telerikNavigation:RadTileViewItem Header="Item1" HeaderTemplate="{StaticResource TileViewItemHeaderTemplate}" ></telerikNavigation:RadTileViewItem>
                    <telerikNavigation:RadTileViewItem Header="Item2" HeaderTemplate="{StaticResource TileViewItemHeaderTemplate}"></telerikNavigation:RadTileViewItem>
                </telerikNavigation:RadTileView>
              
        </Grid>

    and code behind:

    private void Button_Click_1(object sender, RoutedEventArgs e) 
           
               RadTileViewItem itemToRemove = (sender as Button).ParentOfType<RadTileViewItem>(); 
               if (itemToRemove != null
               
                   RadTileView1.Items.Remove(itemToRemove); 
               
           }

    All the best,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Akku
    Akku avatar
    8 posts
    Member since:
    May 2010

    Posted 24 May 2010 Link to this post

    Hello Valentin,

    I tried the same steps mentioned in your reply about implementing Close Button in Tile.

    I am getting an error when i try to close the tile. The difference in your and my RadTileView is, I am adding tiles dynamically.

    Below a code snippet of my work:
                //Add Tile Dynamically 
                DataTemplate dtempClose = (LayoutRoot.Resources["CloseButtonTemplate"as DataTemplate); 
                for (int i = 0; i < numberOfTileViews; i++) 
                { 
                    RadTileView1.Items.Add(new RadTileViewItem() 
                    { 
                        Header = String.Format("TileItem {0}", i), 
                        HeaderTemplate = dtempClose, 
                        Content = new MyTileView() { Text = String.Format("Hello {0}", i)} 
                    }); 
                } 
     
            //Close Tile 
            private void CloseTile(object sender, RoutedEventArgs e) 
            { 
                RadTileViewItem itemToRemove = (sender as Button).ParentOfType<RadTileViewItem>(); 
                if (itemToRemove != null
                    RadTileView1.Items.Remove(itemToRemove); 
            } 

    Error: The given key was not present in the dictionary.

    Please guide me in this regards.

    Thanks,
    Akif Patel
  5. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 27 May 2010 Link to this post

    Hi Akku,

    Sorry for the late response!

    I tried to reproduce the problem with the code you sent, but it is all working on our end. Can you send us the complete project in a support ticket so we can investigate where the problem comes from.

    Thank you in advance for your cooperation!

    Sincerely yours,
    Valentin.Stoychev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top