S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Data Binding

13 Aug 2014, 12:35

I am trying to load a static resource into a button style but it does not seem to be working:

<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 
    <ControlTemplate x:Key="helpicon" TargetType="Control">
          <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
          <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Name="svg3089" Width="512" Height="512"><Canvas.RenderTransform><TranslateTransform X="0" Y="0"/></Canvas.RenderTransform><Canvas.Resources/><!--Unknown tag: metadata--><!--Unknown tag: sodipodi:namedview--><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path3091" Fill="#000000" Data="m0 0h512v512h-512z"/><Canvas Name="g3093"><Canvas.RenderTransform><MatrixTransform Matrix="15 0 0 15 -4304 -2204"/></Canvas.RenderTransform><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path3097" Fill="#FFFFFFFF" Data="m304 148c-8.8366 0-16 7.1634-16 16 0 8.8366 7.1634 16 16 16 8.8366 0 16-7.1634 16-16 0-8.8366-7.1634-16-16-16zm0 4c6.6274 0 12 5.3726 12 12 0 6.6274-5.3726 12-12 12-6.6274 0-12-5.3726-12-12 0-6.6274 5.3726-12 12-12z"/></Canvas><Canvas Name="g3099"><Canvas Name="g3101"><Canvas.RenderTransform><MatrixTransform Matrix="30 0 0 30 -16304 -21954.866"/></Canvas.RenderTransform></Canvas><Canvas Name="g3105"><Canvas.RenderTransform><MatrixTransform Matrix="15 0 0 15 -8864 -13489.433"/></Canvas.RenderTransform><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path3107" Fill="#FFFFFFFF" Data="m608 454c-4.4183 0-8 2.6863-8 6 0 2 4 2 4 0 0-1.1046 1.7908-2 4-2 2.2092 0 4 .8954 4 2 0 1.1046-2 1-4 2-.125 .0625-.2319 .1418-.3125 .2188-1.6523 1.0469-1.6875 2.8429-1.6875 3.7812v1c0 1.108 .892 2 2 2 1.108 0 2-.892 2-2v-1c0-3 6-2.6863 6-6 0-3.3137-3.5817-6-8-6z"><Path.RenderTransform><TranslateTransform X="0" Y="452.36218"/></Path.RenderTransform></Path><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path3109" Fill="#FFFFFFFF" Data="m608 470a2 2 0 0 1 2 2 2 2 0 0 1 -2 2 2 2 0 0 1 -2-2 2 2 0 0 1 2-2"><Path.RenderTransform><TranslateTransform X="0" Y="452.36218"/></Path.RenderTransform></Path></Canvas></Canvas></Canvas>
          </Viewbox>
    </ControlTemplate>
    
    <ControlTemplate x:Key="cancelicon" TargetType="Control">
          <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
          <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Name="svg2" Width="512" Height="512"><Canvas.RenderTransform><TranslateTransform X="0" Y="0"/></Canvas.RenderTransform><Canvas.Resources/><!--Unknown tag: metadata--><!--Unknown tag: sodipodi:namedview--><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path4" Fill="#000000" Data="m0 0h512v512h-512z"/><Canvas Name="g6"><Canvas.RenderTransform><MatrixTransform Matrix="15 0 0 15 -3764 -2204"/></Canvas.RenderTransform></Canvas><Canvas Name="g10"><Canvas.RenderTransform><MatrixTransform Matrix="30 0 0 30 -14144 -21954.866"/></Canvas.RenderTransform><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path14" Fill="#FFFFFFFF" Data="m477.2108 736.3717c-.6099 .1145-1.5089 1.1579-1.1126 1.554l2.4386 2.4378-2.4386 2.4377c-.4877 .4875 .9755 1.9502 1.4632 1.4626l2.4387-2.4377 2.4386 2.4377c.4877 .4876 1.9509-.9751 1.4632-1.4626l-2.4386-2.4377 2.4386-2.4378c.4877-.4875-.9755-1.9501-1.4632-1.4626l-2.4386 2.4377-2.4386-2.4377c-.0915-.091-.2098-.1178-.3506-.091z"/></Canvas><Canvas Name="g16"><Canvas.RenderTransform><MatrixTransform Matrix="15 0 0 15 -3764 -2204"/></Canvas.RenderTransform><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path18" Fill="#FFFFFFFF" Data="m268 148c-8.8366 0-16 7.1634-16 16 0 8.8366 7.1634 16 16 16 8.8366 0 16-7.1634 16-16 0-8.8366-7.1634-16-16-16zm0 4c6.6274 0 12 5.3726 12 12 0 6.6274-5.3726 12-12 12-6.6274 0-12-5.3726-12-12 0-6.6274 5.3726-12 12-12z"/></Canvas></Canvas>
          </Viewbox>
    </ControlTemplate>
    
    <ControlTemplate x:Key="tinkericon" TargetType="Control">
          <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
          <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Name="svg2" Width="512" Height="512"><Canvas.RenderTransform><TranslateTransform X="0" Y="0"/></Canvas.RenderTransform><Canvas.Resources/><!--Unknown tag: metadata--><!--Unknown tag: sodipodi:namedview--><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path4" Fill="#000000" Data="m0 0h512v512h-512z"/><Canvas Name="g6"><Canvas.RenderTransform><MatrixTransform Matrix="18.68858 0 0 18.68858 -1595.78291 -44231.51749"/></Canvas.RenderTransform><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path8" Fill="#FFFFFFFF" Stroke="#FF000000" Data="m103.909 2368.7278c1.593-1.5928 3.9978-1.8378 5.8765-.8023l-3.1443 3.1442c-.5539.5539-.5751 1.4633-.0434 1.995s1.4194.4888 1.9733-.065l3.1442-3.1443c1.0353 1.8786.7906 4.2836-.8023 5.8765-1.2245 1.2245-2.9356 1.6734-4.5104 1.3444l-10.6599 10.6598c.3287 1.5747-.1199 3.2859-1.3443 4.5105-1.593 1.5927-3.9979 1.8375-5.8765.8022l3.1442-3.1443c.5539-.5538.5968-1.4416.0651-1.9733s-1.4411-.5105-1.9949.043l-3.1443 3.1442c-1.0354-1.8786-.7906-4.2835.8024-5.8764 1.2245-1.2244 2.9512-1.6575 4.532-1.3227l10.6597-10.66c-.335-1.5809.0984-3.3073 1.3229-4.5318z"/><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path10" Fill="#FFFFFFFF" Stroke="#FF000000" Data="m110.1284 2393.5471-4.7418-3.0331 .293-2.0209-7.6594-7.6594 1.4595-1.4594 7.6594 7.6594 2.0208-.2931 3.0332 4.7419z"/><Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path12" Fill="#FFFFFFFF" Stroke="#FF000000" Data="m94.6169 2380.6983c-.0435-1.4887-1.1192-2.5644-2.6075-2.6076l-4.7391-4.7391c-3.3415-3.3417 1.1045-8.2646 4.6846-4.6845l4.7611 4.761c.0626 1.4514 1.1119 2.5009 2.5633 2.5634 1.1714 0 2.2544 1.2812 1.1712 2.3645l-3.4475 3.4467c-1.0421 1.0424-2.5168.1512-2.3862-1.1044z"/></Canvas></Canvas>
          </Viewbox>
    </ControlTemplate>
 
</ResourceDictionary>


<Grid
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   mc:Ignorable="d">
	<Grid.Resources>
	<ResourceDictionary Source="iconresource.xaml"/>
		<Storyboard x:Key="animation">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid">
				<EasingDoubleKeyFrame KeyTime="0" Value="-85.5"/>
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
		<Storyboard x:Key="reverseAnimation">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid">
				<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="-88.5"/>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
	</Grid.Resources>

    <Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Top" KeyboardNavigation.DirectionalNavigation="Cycle" RenderTransformOrigin="0.5,0.5">
    	<Grid.RenderTransform>
    		<TransformGroup>
    			<ScaleTransform/>
    			<SkewTransform/>
    			<RotateTransform/>
    			<TranslateTransform/>
    		</TransformGroup>
    	</Grid.RenderTransform>
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
      </Grid.RowDefinitions>

      <Button Style="{StaticResource helpicon}" Padding="20" Grid.Row="1" Grid.Column="0" />
      <Button Style="{StaticResource tinkericon}" x:Name="start" Padding="20" Grid.Row="1" Grid.Column="1" />
      <Button Style="{StaticResource cancelicon}" Padding="20" Grid.Row="1" Grid.Column="2" />
         
    </Grid>
  
</Grid>

 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Data Binding

13 Aug 2014, 16:08

Hi,

The Style property expects a Style object instead of a ControlTemplate. Additionally, you should specify the exact type in the ControlTemplate.TargetType so bindings can be correctly solved:
<ControlTemplate x:Key="helpicon" TargetType="Button" ... />
<Button Template="{StaticResource helpicon}" ... />
Anyway, we have something wrong, because we should notify of this error, and nothing is output to the console when playing this xaml.
 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Data Binding

13 Aug 2014, 20:36

It's giving the error "Resources, property has already being set on 'Grid'."
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Data Binding

14 Aug 2014, 04:08

Yes, I forgot to mention that I changed the xaml because it was not correct.
If you want to include an external ResourceDictionary, you have to use the MergedDictionaries property:
<Grid
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   mc:Ignorable="d">
   <Grid.Resources>
      <ResourceDictionary>
         <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="iconresource.xaml"/>
         </ResourceDictionary.MergedDictionaries>
         <Storyboard x:Key="animation" ... />
         ...
      </ResourceDictionary>
   </Grid.Resources>
   ...
</Grid>
 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Data Binding

14 Aug 2014, 15:20

The icons are showing up in Unity but pressing the button does nothing and the slide in/out animations I made in blend are no longer working, also when opening the project in blend its giving this error:

http://media-cache-ak0.pinimg.com/origi ... 8f01ce.jpg
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Data Binding

14 Aug 2014, 18:46

The icons are showing up in Unity but pressing the button does nothing and the slide in/out animations I made in blend are no longer working,
How did you trigger the animations before?

I attached the following script next to the NoesisGUIPanel component, and when "start" button is clicked, the "animation" is played:
using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{
    Noesis.Storyboard _anim;

    // Use this for initialization
    void Start()
    {
        var gui = GetComponent<NoesisGUIPanel>();
        var root = gui.GetRoot<Noesis.Grid>();
        var btn = root.FindName<Noesis.Button>("start");
        btn.Click += btn_Click;

        _anim = root.FindStringResource<Noesis.Storyboard>("animation");
    }

    void btn_Click(Noesis.BaseComponent sender, Noesis.RoutedEventArgs e)
    {
        _anim.Begin(sender.As<Noesis.FrameworkElement>());
    }
}
also when opening the project in blend its giving this error:
http://media-cache-ak0.pinimg.com/origi ... 8f01ce.jpg
As the error indicates, iconresource.xaml cannot be found. You have to add it to your Blend project: right click in the Tutorial folder, and select "Add Existing Item...", select that xaml and click Ok.
 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Data Binding

14 Aug 2014, 19:40

It opens in blend now but the grid is not showing up in Unity, this is the error its giving.

http://media-cache-ec0.pinimg.com/origi ... ddcec9.jpg


Here is the C# file attached to the main camera that is triggering the animations.

using System;
using UnityEngine;
using InControl;
using Noesis;


namespace BasicExample
{
	public class Controller : MonoBehaviour
	{
		NoesisGUIPanel noesisGUI_;
		private Storyboard _ani;
		private Storyboard _revAni;
		private Grid _root;
		private bool onscreen;
		
		void Start()
		{
			noesisGUI_ = GetComponent<NoesisGUIPanel>();
			_root = noesisGUI_.GetRoot<Grid>();
			_ani = _root.FindStringResource<Storyboard> ("animation");
			_revAni = _root.FindStringResource<Storyboard> ("reverseAnimation");
			var start = _root.FindName<Button>("start");
			start.Focus();

		}
		
		private void Handle(OneAxisInputControl input, Noesis.Key key)
		{
			if (input.WasPressed)
			{
				noesisGUI_.KeyDown(key);
			}
			
			if (input.WasReleased)
			{
				noesisGUI_.KeyUp(key);
			}
		}
		
		private void Handle(InputControl input, Noesis.Key key)
		{
			if (input.WasPressed)
			{
				noesisGUI_.KeyDown(key);
			}
			
			if (input.WasReleased)
			{
				noesisGUI_.KeyUp(key);
			}
		}
		
		void Update()
		{
			// Use last device which provided input.
			var inputDevice = InputManager.ActiveDevice;

			//Full Menu Navigation
//			Handle(inputDevice.Direction.Left, Key.Left);
//			Handle(inputDevice.Direction.Right, Key.Right);
//			Handle(inputDevice.Direction.Up, Key.Up);
//			Handle(inputDevice.Direction.Down, Key.Down);

			//Full Menu Button Press
//			Handle(inputDevice.Action1, Key.Space);

			//Quick Menu Navigation
			Handle(inputDevice.DPadLeft, Key.Left);
			Handle(inputDevice.DPadRight, Key.Right);

			//Quick Display Menu Toggle
//			Handle(inputDevice.DPadUp, Key.Up);

			if (inputDevice.DPadUp.WasPressed)
			{
				onscreen = !onscreen;

				if(onscreen)
				{
					_revAni.Begin(_root);
				}

				else
				{
					_ani.Begin(_root);
				}
			}

			//Quick Button Toggle
			Handle(inputDevice.DPadDown, Key.Space);
		}
	}
}

 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Data Binding

14 Aug 2014, 19:51

The error in the Unity console says it cannot find "Assets/Tutorial/iconresource.xaml".

If the file is found in that path, then try building the resources again (open Window top menu, select NoesisGUI > Settings and click the Build button with DX9 platform at least selected).

Once loaded correctly, the script should work correctly.
 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Data Binding

14 Aug 2014, 20:01

The grid is displaying in Unity now, but none of the default button animations are playing when navigating and pressing them.
 
movra
Posts: 70
Joined: 02 Apr 2014, 20:35

Re: Data Binding

14 Aug 2014, 20:11

Is it possible that the system/theme default button behavior is overwritten by setting their ControlTemplates in iconresource.xaml? But you want to keep the default button behavior and add your own animation on top of it? I know how to interpret your problem, but unfortunately I don't know how to solve it ;)

Who is online

Users browsing this forum: No registered users and 1 guest