Forums

How to find the DataType for the generated bindings
Last Post 09 Jun 2016 01:45 PM by TTFS. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
TTFSUser is Offline
New Member
New Member
Posts:3


--
08 Jun 2016 09:40 PM
    Hey!

    I'm trying to get the compile time generated bindings to work but I already fail at
    specifying the DataType for the ViewModel.


    In your YT video you defined the "vm:" namespace.
    Where does it point?
    What do I need to specify?


    Could you explain the process of setting up a project for
    generated binding so I could understand it better?


    Thanks TTFS.
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:676


    --
    09 Jun 2016 07:17 AM
    It points to namespace and assembly where View Model class is defined. So lets say you have project A with XAML files and project B with View Model. You have to add reference in project A to project B and define namespace in XAML (xmlns).

    So for example in my game i have project EmptyKeys.Strategy.UserInterface with all view models for UI. Then I have project HudControls with XAML files. This project has reference to EmptyKeys.Strategy.UserInterface project and in XAML:

    xmlns:vm="clr-namespace:EmptyKeys.Strategy.UserInterface.ViewModels;assembly=EmptyKeys.Strategy.UserInterface"

    Don't forget to use -bd and /generate-bindings command line options for UI Generator. I use this in post-build event:

    $(ProjectDir)..\..\EmptyKeysUI\Generator\ekUIGen.exe -i=$(ProjectDir) -o=$(ProjectDir)..\Strategy\Game\GeneratedUI\ -oa=$(ProjectDir)..\Strategy\Assets\Shared\UI\ -bd="$(TargetDir)\" /generate-bindings
    


    -bd option tells UI Generator to copy assemblies needed for build of XAML file. If everything is OK, you should see .xaml_bindings.cs files in your generated UI directory.
    TTFSUser is Offline
    New Member
    New Member
    Posts:3


    --
    09 Jun 2016 11:28 AM
    So far i got the generation of the Binding working.
    Thanks for your help with that.

    But I need some help with the ListBox ItemSource.
    It says that the generated classes miss the Properties (i.e. LayerElements and SelectedElement).
    Could you give me an example of a ViewModelClass for Binding generation?
    Or could you point me to a resource so that I can learn what I'm missing from tinkering with it?

    Regards TTFS
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:676


    --
    09 Jun 2016 12:11 PM
    Nothing special there. I have namespace

    xmlns:vm="clr-namespace:EmptyKeys.Strategy.UserInterface.ViewModels;assembly=EmptyKeys.Strategy.UserInterface"

    and controls something like this
     <Grid ek:GeneratedBindings.DataType="{x:Type vm:FactoryPanelViewModel}"> 
        <ListBox Grid.Row="2" ItemsSource="{Binding FactoryItems}" SelectedItem="{Binding SelectedFactoryItem}" Margin="2,0,2,2" /> 
     </Grid> 
     


    and in View Model I have 2 properties.

        public class FactoryPanelViewModel : ViewModelBase
        {  
            private ObservableCollection<FactoryItem> factoryItems;
            private object selectedFactoryItem;
    
            public ObservableCollection<FactoryItem> FactoryItems
            {
                get { return factoryItems; }
                set { SetProperty(ref factoryItems, value); }
            }
    
            public object SelectedFactoryItem
            {
                get { return selectedFactoryItem; }
                set { SetProperty(ref selectedFactoryItem, value); }
            }
    
            ...
    }
    


    There is no additional code required in View Model to have generated bindings. You have to specify DataType in XAML and that's it.
    TTFSUser is Offline
    New Member
    New Member
    Posts:3


    --
    09 Jun 2016 01:45 PM
    Thanks! Now I got it working
    You are not authorized to post a reply.