Page 1 of 1

It seems x:Array isn't implemented (Unknown type 'Array')?

Posted: 08 Feb 2021, 05:16
by devtomilk
Hi there. After several weeks of learning WPF from scratch I'm finally starting to integrate noesisgui to my game(c++/smfl/opengl), and it seems to be working perfectly now.
Now I run into a little "problem", the "play" and "pause" button in the screenshot are actually RadioButtons, and the code below is how I've done it in WPF.
Image
<ControlTemplate.Triggers>
 <Trigger Property="IsMouseOver" Value="True">
 <Setter TargetName="img" Property="Source" Value="{Binding Tag[1], RelativeSource={RelativeSource TemplatedParent}}" />
 </Trigger>
 <Trigger Property="IsChecked" Value="True">
 <Setter TargetName="img" Property="Source" Value="{Binding Tag[2], RelativeSource={RelativeSource TemplatedParent}}" />
 </Trigger>
</ControlTemplate.Triggers>
	    
<RadioButton.Tag>
    <x:Array Type="ImageSource">
        <BitmapImage UriSource="../Images/btnSmallPlay0001.png" />
        <BitmapImage UriSource="../Images/btnSmallPlay0002.png" />
        <BitmapImage UriSource="../Images/btnSmallPlay0003.png" />
    </x:Array>
</RadioButton.Tag>
But since x:Array is not implemented in NoesisGUI yet, I just hard coded them(since there are only 2 buttons), but I'm wondering is there a better way to do this? Thanks a lot!

Re: It seems x:Array isn't implemented (Unknown type 'Array')?

Posted: 08 Feb 2021, 10:45
by sfernandez
Support for generic arrays has been asked in the past, #668, but is not implemented.

There are some alternatives, for example, you can provide your own specific collection:
class ImageSourceCollection: public Noesis::FreezableCollection<ImageSource>
{
    NS_IMPLEMENT_INLINE_REFLECTION_(ImageSourceCollection, Noesis::FreezableCollection<ImageSource>,
        "YourNamespace.ImageSourceCollection")
};
...
Noesis::RegisterComponent<ImageSourceCollection>();
<RadioButton.Tag>
  <local:ImageSourceCollection>
    <BitmapImage UriSource="../Images/btnSmallPlay0001.png" />
    <BitmapImage UriSource="../Images/btnSmallPlay0002.png" />
    <BitmapImage UriSource="../Images/btnSmallPlay0003.png" />
  </local:ImageSourceCollection>
</RadioButton.Tag>
Or changing the template to use resources instead of bindings:
<ControlTemplate.Triggers>
  <Trigger Property="IsMouseOver" Value="True">
    <Setter TargetName="img" Property="Source" Value="{DynamicResource imgOver}"/>
  </Trigger>
  <Trigger Property="IsPressed" Value="True">
    <Setter TargetName="img" Property="Source" Value="{DynamicResource imgPress}"/>
  </Trigger>
</ControlTemplate.Triggers>
<RadioButton.Resources>
  <BitmapImage x:Key="imgNormal" UriSource="Images/btn1-normal.png"/>
  <BitmapImage x:Key="imgOver" UriSource="Images/btn1-over.png"/>
  <BitmapImage x:Key="imgPress" UriSource="Images/btn1-press.png"/>
</RadioButton.Resources>
Could that work for you?

Re: It seems x:Array isn't implemented (Unknown type 'Array')?

Posted: 08 Feb 2021, 10:52
by devtomilk
Wow, thanks for the quick respond. I think this is a much better solution then my current hard-coded one.

Re: It seems x:Array isn't implemented (Unknown type 'Array')?

Posted: 08 Feb 2021, 11:08
by sfernandez
Great, I'll mark this post as solved.

Re: It seems x:Array isn't implemented (Unknown type 'Array')?

Posted: 24 Aug 2022, 16:19
by pdx_hoda_ismail
Thank you!