Trouble traversing Visual Tree in C++/WinRT - c++-winrt

I'm implementing an app w/ Excel-style functionality where I have a ListBox of baskets, each containing a ListBox of Items, each containing a StackPanel-nested Button inside it.
XAML, What the layout looks like
Goal: I want to click on the button, such that the item entry (StackPanel) is highlighted via SelectedIndex(). I try to accomplish this in the GotFocus="ItemGotFocus" event handler, by traversing the visual tree to find the parent ListBox, so I can call SelectedIndex() on it.
However, I am getting errors whenever I call VisualTreeHelper::GetParent() or other functions from the namespapce in general:
Do I need to define a template definition somewhere, so it can figure out the type I want it to return, or is there a better way to go about this?

Thank you, it worked!
Turns out I had included <winrt/Microsoft.UI.Xaml.Media.h> in "pch.h", when what I really needed was <winrt/Windows.UI.Xaml.Media.h>.

Related

How do i manipulate the data templates inside listbox in uwp

I am making a chat application using XAML in UWP.The side panel is consisting of users. like this.
Everything is in Listbox in which I have this template that consists one ellipse as a circle which is like an indicator,one user image,textblocks and one toggle switch.I have to give states to the toggle switch in on the state it should change the green color of circle and make it red.
I want to give this functionality in code c# in MainPage.cs. I made the object of toggle in toggled Event Handler but I am not able to access the other elements inside the data template like ellispse,textblock.
What is the other alternative way of doing this?
NOTE: It has to be in listbox because I want to use the same template for every user.
The best way to do this would be to use data binding.
You would define a ViewModel class for the item, which would contain a bool property and would react to the toggling of the switch in the setter or have a Command which you would execute when the state event changes using behaviors.
If you really want the code as a event handler on main page, you have some options. To get the item associated with the toggle, you can use its DataContext property and cast it to the data type you are using. Alternatively, you can use Visual Tree Extesnions provided by the UWP Community Toolkit. This enables you to find the parent (probably Grid) where you store all the item controls and then manually find the user image, TextBlock, etc.

Add custom control to toolbox and have its properties show up in the properties window

To illustrate what I'm asking, let's say I have a custom TextBox that has 2 modes. Mode 1 only allows numbers, and mode 2 only allows dates in a particular format.
Using a class module I can create this custom TextBox, and I can use a loop when the userform initialises to set which TextBoxes are custom.
What I'd like to happen is have the custom TextBox, or what ever custom control I want, show up in the toolbox. And I also want its custom properties, if they exist, to show up in the property window.
So far, I've been unable to find a way to do this. In fact, I've been unable to find out if it's even possible. It seems, to me anyway, that it's something that should be possible, but maybe I'm barking up the wrong tree. If it's possible I'd really appreciate being pointed to a resource.

How Can I Pass An Event Handler Outside Of A Custom Class

I have created a custom Textbox using a new class of which inherits. To this custom Textbox I have added two buttons (embedded) inside the control which are both declared inside the class. One button is for Search and the other for Clear.
The purpose behind these buttons is to populate a Listview control when using Search and Clear the results when using clear...pretty straight forward.
However, my issue that I need help with is...
Because I have declared these buttons inside of my custom class, I cannot work out how to pass a 'Click' event outside of the class and back to the form. For example, if I type into the Textbox and hit the search button, I somehow need to execute code on the click event (and same for clear).
I have read a little about not being able to pass event handlers outside of the class it was created, but I'm not really familiar with this.
Is there/and if so what is the best way to achieve my results? Is it possible to handle a click event outside of the class to pass information to other controls?
Any help appreciated. Thanks
Thanks to the comments from Hans Passant for putting me on the right track, I was able to refer to this site Raising Events and solve my issue.

Create a shared copy and paste menu for my grids

I have 20 or so grids in my application suite. I'd like to create a global copy/paste context menu which I can bind to every single grid rather than code in each form.
I am unsure what is the best way to achieve this, I have started to create a class with my menu in it, but get stuck at the point of adding the actual menu options. For example I know I'll need to call a "copy" event, but I also know I'll need to tell it what I am copying, and I cannot see how that is done in vb.net when you can only add the address of a method minus parameters.
e.g.
.MenuItems.Add("Copy Cell", New System.EventHandler(AddressOf CopyCell))
Obviously I want "CopyCell" to only be coded in one place as well, rather than repeated in each form. I will always be copying the same object (SelectedCellCollection).
I am not sure how to make the menu have an event with parameters, or how to make it "know" that I want to always copy the selected items. I'm aware that I'd have to do some coding in the form but just trying to work out the way to minimize it.
I have created my own context menu class (via inheritance) with specific copy and paste functionality / options tailored to the grid I am using. It works fine and only needs one line of code per form/grid to activate.

Removing item level mouseover effect in SharePoint 2010

I am trying to remove the hover effect that brings up the checkbox next to the row item in SharePoint 2010 list item rows. Is there any settings that can make this happen? I would like to keep away from having to tinker with the CSS and javascripts. Please see illustration below. Thank you.
There are no settings for that sort of thing - the selection check box is a default behavior. You are going to have to modify the CSS, for that.
Use SharePoint Designer (Available Here]1) to help determine whitch CSS elements control that behavior, and make a custom style sheet to override it.
You can accomplish this by going to the Modify View option of your list and unchecking the Allow Individual Item Checkboxes under Tabular View options.
Note: If you are using a Web Part to view it you might have to set the view again for the changes to reflect.