Re: A few questions about some features
Posted: 23 Feb 2015, 17:21
How do you accessed the property? Do you mean in the XAML or by code?
Welcome to our official discussion site. You’ll find topics on features, bugs, development, and general support here
https://www.noesisengine.com/forums/
< [CustomControl] Orientation="Vertical" />
<Border
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
HorizontalAlignment="Center" VerticalAlignment="Center"
x:Name="PART_BorderTest"
UseLayoutRounding="True">
<FilterBar x:Name="PART_FilterBar" />
</Border>
<FilterBar
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="FilterBar" x:Name="FilterBar"
UseLayoutRounding="True">
<StackPanel x:Name="PART_CategoryPanel" Orientation="Horizontal" />
</FilterBar>
<FilterCategory
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="FilterCategory" x:Name="FilterCategory"
UseLayoutRounding="True">
<FilterCategory.Resources>
<ControlTemplate x:Key="MenuAnchorTemplate" TargetType="{x:Type MenuAnchor}">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<ContentPresenter x:Name="PART_HeaderContent"
Content="{Binding HeaderContent, RelativeSource={RelativeSource TemplatedParent}}"/>
<ToggleButton IsChecked="{Binding IsMenuOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
</StackPanel>
<Popup x:Name="PART_Popup"
IsOpen="{Binding IsMenuOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Focusable="False"
PlacementTarget="{Binding ElementName=PART_HeaderContent}"
Placement="Bottom"
PopupAnimation="Slide"
VerticalOffset="1"
AllowsTransparency="True"
StaysOpen="True">
<ContentPresenter/>
</Popup>
</StackPanel>
</ControlTemplate>
<Style TargetType="{x:Type MenuAnchor}">
<Setter Property="Template" Value="{StaticResource MenuAnchorTemplate}"/>
</Style>
</FilterCategory.Resources>
<MenuAnchor>
<MenuAnchor.HeaderContent>
<StackPanel Orientation="Horizontal">
<CheckBox/>
<TextBlock Text="{Binding CategoryID, Mode=TwoWay, StringFormat=F2}" />
</StackPanel>
</MenuAnchor.HeaderContent>
<StackPanel x:Name="PART_FilterPanel" Orientation="Vertical"/>
</MenuAnchor>
</FilterCategory>
Noesis::Gui::UIElementCollection* pCol = _filtersCategoriesPanel->GetChildren();
if (pCol != nullptr)
{
pCol->Add(pNewCategory);
}
NoesisGUI UI elements take ownership of the objects you set in them. For example, when setting the ContentControl.Content property, the control keeps a reference to its content, so it isn't destroyed while it is being used. The same occurs for a brush set as Control.Background, etc.Hi,
I have a question about memory management in general. I'm spawning controls with their data context in my application code and I'm wondering who "owns" these things once passed to Noesis. Will the framework delete these entities or should I take care of these myself? What is the best practice for this kind of use?
void SetText(ContentControl* control, const NsChar* text)
{
Ptr<TextBlock> tb = *new TextBlock(text); // Ptr keeps a reference to the new TextBlock (1 ref)
Ptr<Brush> fg = *new SolidColorBrush(Colors::Red()); // Ptr keeps a reference to the new Brush (1 ref)
tb->SetForeground(fg.GetPtr()); // TextBlock grabs a reference to the Brush (2 refs now)
control->SetContent(tb.GetPtr()); // ContentControl grabs a reference to the TextBlock (2 refs now)
}
// Ptrs are out of scope and destroyed, releasing their references. TextBlock and Brush with 1 ref now
I'll take a look at these two problems and let you know when find something.I also have a problem with my custom drop down menu...
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="InventoryTile" x:Name="ROOT_InventoryTile">
<UserControl.Resources>
<ResourceDictionary x:Key="ResDics">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Key="ResDics" Source="itemIcons.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<ResourceArgConverter x:Key="ResArgConverter"/>
<InventoryTileModel x:Key="dataModel" ItemID="1" Quantity="42"/>
</UserControl.Resources>
<Border DataContext="{StaticResource dataModel}"
BorderBrush="Gray" BorderThickness="1">
<StackPanel
HorizontalAlignment="Center" VerticalAlignment="Center"
Orientation="Vertical">
<Image Source="{Binding ItemID,
Converter={StaticResource ResArgConverter},
ConverterParameter={StaticResource ResDics}}"
Height="60" Width="60"/>
<TextBlock
HorizontalAlignment="Center"
Text="{Binding Quantity}" />
</StackPanel>
</Border>
</UserControl>
NsBool TryConvert(Noesis::Core::BaseComponent* value,
const Noesis::Core::Type* targetType,
Noesis::Core::BaseComponent* parameter,
Noesis::Core::Ptr<Noesis::Core::BaseComponent>& result)
{
Noesis::Core::BaseComponent* pResult = nullptr;
if (nullptr != value)
{
Noesis::Gui::ResourceDictionary* pParam = Noesis::Core::Boxing::Unbox<Noesis::Gui::ResourceDictionary*>(parameter);
NsInt32 intKey = Noesis::Core::Boxing::Unbox<NsInt32>(value);
std::string strKey = std::to_string(intKey);
const NsChar* charKey = strKey.c_str();
Noesis::Core::Ptr<Noesis::Gui::ResourceKeyString> pResKeyStr = Noesis::Gui::ResourceKeyString::TryCreate(charKey);
if (nullptr != pParam && 0 != pResKeyStr)
{
pResult = pParam->TryGet(pResKeyStr);
if (nullptr != pResult)
{
result.Reset(pResult);
}
}
}
return nullptr != pResult;
}
NsBool TryConvert(Noesis::Core::BaseComponent* value,
const Noesis::Core::Type* targetType,
Noesis::Core::BaseComponent* parameter,
Noesis::Core::Ptr<Noesis::Core::BaseComponent>& result)
{
Noesis::Core::BaseComponent* pResult = nullptr;
if (nullptr != value)
{
// if you are sure of the parameter type use NsStaticCast, if you don't know call NsDynamicCast
// and check for null
Noesis::Gui::ResourceDictionary* pParam = NsStaticCast<Noesis::Gui::ResourceDictionary*>(parameter);
// you can use ToString to get a string representation of a boxed value
Noesis::Core::Ptr<Noesis::Gui::ResourceKeyString> pResKeyStr =
Noesis::Gui::ResourceKeyString::TryCreate(value->ToString().c_str());
if (nullptr != pParam && 0 != pResKeyStr && pParam->Find(pResKeyStr.GetPtr(), pResult))
{
result.Reset(pResult);
return true;
}
}
result.Reset();
return false;
}
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="InventoryTile" x:Name="ROOT_InventoryTile">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary x:Key="ResDics" Source="itemIcons.xaml"/>
<ResourceArgConverter x:Key="ResArgConverter"/>
<InventoryTileModel x:Key="dataModel" ItemID="1" Quantity="42"/>
</ResourceDictionary>
</UserControl.Resources>
<!-- ... -->
</UserControl>
<Border
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Root"
BorderBrush="White" BorderThickness="1"
HorizontalAlignment="Center" VerticalAlignment="Center">
<!--<Border.Resources>
<ResourceDictionary>
<InventoryTileModel x:Key="model" ItemID="0" Quantity="10" />
</ResourceDictionary>
</Border.Resources>-->
<Image
Source="./assets/woodicon.png"
Height="60" Width="60" />
</Border>
File Core\Kernel\Src\Memory.cpp (l. 130): Not enough memory! (malloc(15627680408))
class InventoryTileModel : public Noesis::Core::BaseComponent
{
public:
InventoryTileModel()
: _itemID(-1)
, _quantity(-1)
{}
InventoryTileModel(int inID, int inQuantity)
: _itemID(inID)
, _quantity(inQuantity)
{}
~InventoryTileModel() {}
int GetItemID() const { return _itemID; }
void SetItemID(int inID) { _itemID = inID; }
int GetQuantity() const { return _quantity; }
void SetQuantity(int inQuantity) { _quantity = inQuantity; }
/** BaseComponent interface **/
void Serialize(Noesis::Core::SerializationData* data) const;
void Unserialize(Noesis::Core::UnserializationData* data, NsUInt32 version);
/**/
private:
int _itemID;
int _quantity;
NS_IMPLEMENT_INLINE_REFLECTION(InventoryTileModel, Noesis::Core::BaseComponent)
{
NsMeta<Noesis::Core::TypeId>("InventoryTileModel");
NsProp("ItemID", &InventoryTileModel::GetItemID, &InventoryTileModel::SetItemID);
NsProp("Quantity", &InventoryTileModel::GetQuantity, &InventoryTileModel::SetQuantity);
}
};