-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: translation resource directionary
Cool :)
Thanks for the update.
Thanks for the update.
Re: translation resource directionary
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.
Re: translation resource directionary
This is more a me problem than a you problem I guess. But let me try to explain. As you may remember from my first beginner questions I started the transition to Noesis at the beginning of this year with no prior knowledge of XAML. Now the XAML part is the easy one. Creating layouts is not much different than in any other UI description language. In the end everything is a Grid or Stackpanel.
I struggled more with data bindings and interactivity. Most of the time I try something, then it doesn't work, then I need to figure out why it doesn't work. It doesn't help that XAML is C# centric and when you google something most examples are in C#. 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. Why does it have to be that complicated? I had that feeling a few times during the last months while working on this without specifically remembering what it was now.
I'm also someone learning most things from examples. So having my color converter now and knowing how and where to implement it will help with all other needed converters in the future.
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?
I struggled more with data bindings and interactivity. Most of the time I try something, then it doesn't work, then I need to figure out why it doesn't work. It doesn't help that XAML is C# centric and when you google something most examples are in C#. 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. Why does it have to be that complicated? I had that feeling a few times during the last months while working on this without specifically remembering what it was now.
I'm also someone learning most things from examples. So having my color converter now and knowing how and where to implement it will help with all other needed converters in the future.
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?
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: translation resource directionary
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?
Code: Select all
<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>Code: Select all
<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>Code: Select all
Grid* topWindows = FindName<Grid>("TopWindows");
topWindow->GetChildren()->Add(messageWindow);
//...
topWindow->GetChildren()->Remove(messageWindow);-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: translation resource directionary
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.
Code: Select all
<ToggleButton>
<ToggleButton.Background>
<SolidColorBrush Color="{Binding Activity, Converter={StaticResource ActivityColorConverter}}"/>
</ToggleButton.Background>
</ToggleButton>Code: Select all
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;
}Code: Select all
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);
}
};Code: Select all
<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>Who is online
Users browsing this forum: No registered users and 179 guests