UXDock + MVVM Example and questions

13 replies. Last post: April 11, 2011 9:56 PM by Handy Surya
Tags :
  • New Discussion
  • New Question
  • New Product Feedback

Hi

Where can I get a project sample of UXDock with MVVM? None of the samples use UXDock with MVVM. 

I have tried to recreate a project based on the helpfile's MVVM exaple of ButtonObject and ItemObject. It works up to a point but I'm having a couple of issues.

1. The images of the UxDockButtons work file but the images of the sub items(UxStackItem?) do not work, only the text is displayed. 

2. How do I link up a click command to the actual ItemObject. I want to be able to add a command to the ItemObject and bind the click event to this command.


Below are the code I'm using as from the example.


<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:Intersoft="http://intersoft.clientui.com/schemas"
		xmlns:vm="clr-namespace:Intersoft"
		xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		mc:Ignorable="d"
		x:Class="Intersoft.MainWindow"
		x:Name="Window"
		Title="MainWindow"
		Width="640"
		Height="480">
        <Grid x:Name="LayoutRoot" Background="White">
        <Grid.DataContext>
            <vm:MainPageViewModel/>
        </Grid.DataContext>
        <Intersoft:UXDock 
		 ItemsSource="{Binding Buttons}" DisplayMemberPath="Text"  ImageMemberPath="Image" CollectionMemberPath="SubItems"/>
    </Grid>
</Window>
public class ButtonObject: INotifyPropertyChanged
    {
        private ObservableCollection<ItemObject> _subItems;
        private string _text;
        private string _image;
        public ObservableCollection<ItemObject> SubItems
        {
            get { return this._subItems; }
            set
            {
                if (this._subItems != value)
                {
                    this._subItems = value;
                    this.OnPropertyChanged("SubItems");
                }
            }
        }
        public string Text
        {
            get { return this._text; }
            set
            {
                if (this._text != value)
                {
                    this._text = value;
                    this.OnPropertyChanged("Text");
                }
            }
        }
        public string Image
        {
            get { return this._image; }
            set
            {
                if (this._image != value)
                {
                    this._image = value;
                    this.OnPropertyChanged("Image");
                }
            }
        }
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
public class ItemObject : INotifyPropertyChanged
    {
        private string _text;
        private string _image;
        public string Text
        {
            get { return this._text; }
            set
            {
                if (this._text != value)
                {
                    this._text = value;
                    this.OnPropertyChanged("Text");
                }
            }
        }
        public string Image
        {
            get { return this._image; }
            set
            {
                if (this._image != value)
                {
                    this._image = value;
                    this.OnPropertyChanged("Image");
                }
            }
        }
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }

 public class MainPageViewModel : INotifyPropertyChanged
    {
		 public MainPageViewModel()
        {
            this.Buttons = new ObservableCollection<ButtonObject>();
            this.Buttons.Add(new ButtonObject() { Text = "Home", Image = "robot.png" });
            this.Buttons.Add(new ButtonObject() { Text = "Clock", Image = "robot.png" });
            this.Buttons.Add(new ButtonObject() { Text = "Photo", Image = "robot.png" });
            this.Buttons.Add(new ButtonObject() { Text = "Mail", Image = "robot.png" });
            ButtonObject document = new ButtonObject() { Text = "Document", Image = "robot.png" };
            document.SubItems = new ObservableCollection<ItemObject>();
            document.SubItems.Add(new ItemObject() { Text = "Video", Image = "robot.png" });
            document.SubItems.Add(new ItemObject() { Text = "Picture", Image = "robot.png" });
            document.SubItems.Add(new ItemObject() { Text = "Music", Image = "robot.png" });
            document.SubItems.Add(new ItemObject() { Text = "Text", Image = "robot.png" });
            this.Buttons.Add(document);
        }
        private ObservableCollection<ButtonObject> _buttons;
        public ObservableCollection<ButtonObject> Buttons
        {
            get { return this._buttons; }
            set
            {
                if (this._buttons != value)
                {
                    this._buttons = value;
                    this.OnPropertyChanged("Buttons");
                }
            }
        }
        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }

 


All times are GMT -5. The time now is 1:40 AM.
Previous Next