Guest User

Untitled

a guest
Sep 21st, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. You can only retrieve your UserControl by name from the template, so you'll need to supplement your UserControl with the following method:
  2.  
  3. public ToggleButton FindToggleButton()
  4. {
  5.    //since the ToggleButton inside the control has a name ("PART_ToggleButton"), we can simply access it via a field of the same name
  6.    return PART_ToggleButton;
  7. }
  8.  
  9. Just put this method in your control's code-behind.
  10.  
  11. Then you need to modify the method retrieving the ToggleButton from the ListView:
  12.  
  13. ...
  14. //first we retrieve the GroupItem control associated with current second-level group
  15. var container = listView.ItemContainerGenerator.ContainerFromItem(leagueGroup) as GroupItem;
  16. //then we find the named FavouriteControl inside the template
  17. var favouriteControl = container.Template.FindName("PART_FavouriteControl", container) as FavouriteControl;
  18. var toggleButton = favouriteControl.FindToggleButton();
  19.  
  20. Note that to avoid confusion I used the name "PART_FavouriteControl", so you need to update your GroupItem template accordingly, so that it has:
  21.  
  22. <LSControls:FavouriteControl x:Name="PART_FavouriteControl" (...)>
Advertisement
Add Comment
Please, Sign In to add comment