devtomilk
Topic Author
Posts: 3
Joined: 01 Sep 2020, 07:50

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

08 Feb 2021, 05:16

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!
 
User avatar
sfernandez
Site Admin
Posts: 2327
Joined: 22 Dec 2011, 19:20

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

08 Feb 2021, 10:45

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::BaseFreezableCollection, "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?
 
devtomilk
Topic Author
Posts: 3
Joined: 01 Sep 2020, 07:50

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

08 Feb 2021, 10:52

Wow, thanks for the quick respond. I think this is a much better solution then my current hard-coded one.
 
User avatar
sfernandez
Site Admin
Posts: 2327
Joined: 22 Dec 2011, 19:20

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

08 Feb 2021, 11:08

Great, I'll mark this post as solved.

Who is online

Users browsing this forum: Bing [Bot] and 3 guests