locked
Editing an existing Project... stumbling blocks. RRS feed

  • General discussion

  • So I just got into expression blend and scoured the internet for some issues I'm having and no luck.

    1) My project existed long before expression blend, and i just recently got my game engine running in a wpf hosted window.
    E B crashes every once in a while when i try to click on an element, any idea why this might happen?

    here is a picture of the basics of what I have and as you can see its in need of simple design. Here is the xaml.

    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:loc="clr-namespace:GravEdit"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="GravEdit.MainWindow"
        Title="GravEdit" Height="800" Width="800" mc:Ignorable="d">
        <DockPanel LastChildFill="True">
            <loc:GravMenu DockPanel.Dock="Top"/>
            <ItemsControl x:Name="PropertyGrid" ItemsSource="{Binding Table}" Width="200">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Text="{Binding Key}"/>
                            <TextBox Grid.Column="1"   Text="{Binding Value.Value}"/>    
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            <Separator DockPanel.Dock="Right"/>
        <WindowsFormsHost x:Name="OpenGlPanel" Width="500" Height="500" Margin="0,0,0,121.52" VerticalAlignment="Top" d:LayoutOverrides="Height" HorizontalAlignment="Center"/>
            </DockPanel>
    </Window>
    

    I would like to make some design changes to the itemcontrol that i have (maybe make it a usercontrol from scratch like i did the menu), although when i look at it in EB it doesnt show the grid or text blocks. why is this?
    I would also like to add a 2 list views for objects and modules i would like to show ... (basically drag and drop different ones in the scene to have them added, similar to how EB works haha). 

    Lastly, I bind an observable collection to my item control and cannot find where i can do this in EB, and where i can see (or add for that matter) a listitem to customize the two listboxes. I should note that Table belongs to MainWindow.

    EDIT: I'm also thinking about moving to the Grid for master layout... any comments on this?

    Any help would be greatly appriciated, and would greatly reduce my learning curve. 
    Thanks.
    Joe



    Sunday, February 28, 2010 7:07 AM

All replies

  • If you are experiencing a crash, could you run Blend with the /exceptionlog flag turned on and post the information you get after a crash in the forums?  This will help us investigate the problem.

    To edit the items template, right click the itemscontrol in the objects and timeline panel (or the artboard) and select edit additional templates -> Item template -> edit current, then you should see the grid and text blocks.

    To work with the data binding, select the items control, then in the properties panel you should find the ItemsSource property has a yellow line around it, and a yellow filled box to the right, click on the box and select databinding.


    While there is no single right answer about layout containers, grid is probably the most flexible, and you get row/column resizing with grid splitters, which can be very useful.

    Monday, March 1, 2010 3:03 PM
    Moderator
  • Are you starting a DispatcherTimer in any of your constructors?  If that is the case you should check to see if you are running in design mode(Inside blend/VS) by using DesignerProperties.GetIsInDesignMode to prevent starting the timer.

    -Scott

    Monday, March 1, 2010 6:34 PM

  • To edit the items template, right click the itemscontrol in the objects and timeline panel (or the artboard) and select edit additional templates -> Item template -> edit current, then you should see the grid and text blocks.


    I did this and it only showed a Border and ItemPresenter, not the Grid and textblocks you see in the above xaml.

    I will definitely do the exceptionlog when i get home. I don't think im setting a DispatcherTimer anywhere.

    For the data binding ... here is my source with my observable collections im trying to bind to.

    namespace GravEdit
        {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
            {
            private GravWrap gravWrap = new GravWrap();
            public ILua LuaPortal;
    
            private DataLayer data = new DataLayer();
    
            public MainWindow()
                {
                this.DataContext = this.data;
                this.data.Stuff = new ObservableCollection<string>();
               
    
                try
                    {
                    InitializeComponent();
                    System.Windows.Forms.Panel panel = new System.Windows.Forms.Panel();
                    this.OpenGlPanel.Child = panel;
                    panel.Width = (int)this.OpenGlPanel.Width;
                    panel.Height = (int)this.OpenGlPanel.Height;
                    IntPtr LuaState = this.gravWrap.Initialize(panel.Handle.ToInt32());
                    LuaPortal = new ILua(LuaState);
    
                   
                    LuaPortal.lua.NewTable("woot");
                    LuaTable table = LuaPortal.lua.GetTable("woot");
                    this.data.Table = new ObservableLuaTable<string, EditableValue>(table);
                    this.data.Table.Add(new KeyValuePair<string, EditableValue>("1", new EditableValue("1value")));
                    this.data.Table.Add(new KeyValuePair<string, EditableValue>("2", new EditableValue("2value")));
                    this.data.Table.Add(new KeyValuePair<string, EditableValue>("3", new EditableValue("3value")));
                    this.data.Stuff = LuaPortal.Mods.Mods;
    
                    GravObject TestObj = new GravObject("Core.Camera.FreeCamera");
                    
    
                    }
                catch (Exception ex)
                    {
                    MessageBox.Show(ex.Message);
                    }
                }
    
            private void Button_Click(object sender, RoutedEventArgs e)
                {
                this.data.Stuff.Add("More!");
                }
    
           
            private class DataLayer : INotifyPropertyChanged
                {
                private ObservableCollection<string> stuff;
                private ObservableLuaTable<string, EditableValue> table;
                private ObservableCollection<GravObject> instances;
    
                public ObservableCollection<string> Stuff
                    {
                    get
                        {
                        return this.stuff;
                        }
                    set
                        {
                        if (this.stuff != value)
                            {
                            this.stuff = value;
                            this.OnPropertyChanged("Stuff");
                            }
                        }
                    }
    
                public ObservableCollection<GravObject> Instances
                {
                    get
                    {
                        return this.instances;
                    }
                    set
                    {
                        if (this.instances != value)
                        {
                            this.instances = value;
                            this.OnPropertyChanged("Instances");
                        }
                    }
                }
    
                public ObservableLuaTable<string, EditableValue> Table
                    {
                    get { return this.table; }
                    set
                        {
                        if (this.table != value)
                            {
                            this.table = value;
                            this.OnPropertyChanged("Table");
                            }
                        }
                    }
    
                public DataLayer()
                    {
                    }
    
                public event PropertyChangedEventHandler PropertyChanged;
    
                private void OnPropertyChanged(string propertyName)
                    {
                    if (this.PropertyChanged != null)
                        {
                        this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                        }
                    }
                }
    When i select binding in the itemsource i can select MainWindow, but i cannot find, in MainWindo'ws Properties, where i would set the datalayer's observable collections.

    I realize that i am doing this from a developers point of view (ie just trying to get stuff working and not really sticking to a design pattern). If switching to mvvm would fix some of these issues then I'm willing to change (better now then later).

    Thanks for the help,
    Joe
    Monday, March 1, 2010 7:30 PM
  • One thing, I notice i declare the item.template inside the itemscontrol, where when i try to edit the template in expression blend, it creates it as a resource. Could this have to do with it not showing up correctly?



    Monday, March 1, 2010 9:05 PM

  • To edit the items template, right click the itemscontrol in the objects and timeline panel (or the artboard) and select edit additional templates -> Item template -> edit current, then you should see the grid and text blocks.


    I did this and it only showed a Border and ItemPresenter, not the Grid and textblocks you see in the above xaml.
     
    I believe you selected "Edit Template" -> Edit a copy, when you need to select "Edit Additional Templates" -> "Item template" -> "Edit Current".  It is confusing because a listbox/itemscontrol has several different templates, but the one you want to edit is the Item Template. 

    In the binding window, you have the option to use an explicit data context (which it will be set to because of your xaml), or select element properties, or things that are declared in xaml.  If you were to declare your data layer objects in xaml (you can do so on the data field tab, if you make your data class public and not nested, use the +CLR object button), you should be able to use the binding tools more effectively.  You can get to the DataLayer declared in xaml using something like this: this.Resources["key"] as DataLayer.

    Hope that helps, please feel free to post more questions if this isn't clear enough.
    Tuesday, March 2, 2010 3:18 PM
    Moderator
  • Excellent,

    This totally makes sense now!

    In my brief use of EB last night there were no crashes, so far so good.

    I will give the binding stuff a try.

    -Joe



    Tuesday, March 2, 2010 8:35 PM