Setting parent
Posted: 30 Apr 2015, 21:09
I have a function where I create a border control and I give it a background based on a resource name. After this function is done I don't see anything and I'm guessing it's because it has no parent. How can I set the parent and is there anything else I'm missing here? I get that I have a memory leak with this but I'll store the border in a list later I just want to get it displayed on screen and test with different resolutions.
The parent would be a Grid control so would also need to know how to set this items position as well.
Code: Select all
int LuaNoesis::CreateItem(lua_State* L)
{
int iconHeight = lua_tonumber(L, -1);
int iconWidth = lua_tonumber(L, -2);
string itemName = lua_tostring(L, -3);
// get 1 inventory slot so we can get it's size to help us resize our new item so it matches the sceen resolution since the inventory slots automatically scale based on screen resolution
UIElement* e = uiRenderer->GetXAML()->FindName<UIElement>("_00");
// create a border element where the image inside is the resource item name and where the size of the border is the width and height multiplied by the size of 1 inventory slot (since this can change based on res)
Border* item = new Border();
Ptr<ResourceKeyString> key = ResourceKeyString::Create(itemName.c_str());
ImageBrush* itemIcon = uiRenderer->GetXAML()->FindResource<ImageBrush>(key.GetPtr());
item->SetBackground(itemIcon);
item->SetWidth(e->GetRenderSize().width);
item->SetHeight(e->GetRenderSize().height);
return 0;
}