Re: translation resource directionary
Posted: 09 Nov 2020, 18:45
Cool :)
Thanks for the update.
Thanks for the update.
Welcome to our official discussion site. You’ll find topics on features, bugs, development, and general support here
https://www.noesisengine.com/forums/
Could you please elaborate about this? We are always trying to improve our API.Was a difficult birth as usual and more than I like but in the end it works.
There is no such example, but using MouseDragElementBehavior you can move any UI element inside the bounds of a container using the mouse.While we're at it, do you have an example (in C++ would be nice) of a dragable window that could be positioned anywhere on the screen on top of a layout. Is that even possible with Noesis?
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions">
<Border Background="Silver" Margin="100">
<Rectangle Width="100" Height="50" Fill="Red">
<i:Interaction.Behaviors>
<ei:MouseDragElementBehavior ConstraintToParentBounds="True" />
</i:Interaction.Behaviors>
</Rectangle>
</Border>
</Grid><UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot">
<!-- your UI here -->
<Grid x:Name="TopWindows"></Grid>
</Grid>
</UserControl>Grid* topWindows = FindName<Grid>("TopWindows");
topWindow->GetChildren()->Add(messageWindow);
//...
topWindow->GetChildren()->Remove(messageWindow);In the Localization demo I put as an example before we defined a SolidColorBrush in xaml so the Converter could return a Color directly, which will be better to avoid creating new brush objects every time the binding changes:For example setting the color to a button according to some value in code. I take it you reimplemented WPF functionality here and this is how it works and you can't do much about it. But for a newcomer it's pretty hard to understand why I simply can't set a color to an UI element.
<ToggleButton>
<ToggleButton.Background>
<SolidColorBrush Color="{Binding Activity, Converter={StaticResource ActivityColorConverter}}"/>
</ToggleButton.Background>
</ToggleButton>bool TryConvert( BaseComponent* value, const Noesis::Type* targetType, BaseComponent*, Noesis::Ptr<BaseComponent>& result )
{
if ( targetType == Noesis::TypeOf<Noesis::Color>() )
{
result = Noesis::Boxing::Box( Noesis::Color( 255, 0, 255 ) );
return true;
}
return false;
}struct ActivityBrushConverter: BaseValueConverter
{
ActivityBrushConverter(): _resources(MakePtr<ResourceDictionary>()) { }
ResourceDictionary* GetResources() const { return _resources; }
bool TryConvert(BaseComponent* value, const Type*, BaseComponent*, Ptr<BaseComponent>& result) override
{
if (Boxing::CanUnbox<Activity>(value))
{
switch (Boxing::Unbox<Activity>(value))
{
case Activity::None: result.Reset(_resources->Get<Brush>("None")); break;
case Activity::Eat: result.Reset(_resources->Get<Brush>("Eat")); break;
case Activity::Sleep: result.Reset(_resources->Get<Brush>("Sleep")); break;
...
}
}
return result != nullptr;
}
private:
Ptr<ResourceDictionary> _resources;
NS_IMPLEMENT_INLINE_REFLECTION(ActivityBrushConverter, BaseValueConverter, "MyNamespace.ActivityBrushConverter")
{
NsProp("Resources", &ActivityBrushConverter::GetResources);
}
};<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNamespace">
<Grid.Resources>
<local:ActivityBrushConverter x:Key="activityBrushConverter">
<local:ActivityBrushConverter.Resources>
<SolidColorBrush x:Key="None" Color="Transparent"/>
<SolidColorBrush x:Key="Eat" Color="Pink"/>
<SolidColorBrush x:Key="Sleep" Color="Blue"/>
...
</local:ActivityBrushConverter.Resources>
</local:ActivityBrushConverter>
</Grid.Resources>
<ToggleButton Background="{Binding Activity, Converter={StaticResource activityBrushConverter}}"/>
</Grid>