Home Forums WPF controls Xceed Toolkit Plus for WPF AvalonDock. Cannot fire "Tools->Properties" in Prism

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #41772 |

    I am using AvalonDock. This code works okay in simple MVVM application(without Prism) – “MenuItem” is fired always.

    What I have:

    <UserControl x:Class="ModuleCAvalonDock.ViewC">
    <Menu>
            <MenuItem Header="File">
                <MenuItem Header="New" Command="{Binding NewCommand}"/>
                <MenuItem Header="Open" Command="{Binding OpenCommand}"/>
                <Separator/>
                <MenuItem Header="Save" Command="{Binding ActiveDocument.SaveCommand}"/>
                <MenuItem Header="Save As..." Command="{Binding ActiveDocument.SaveAsCommand}"/>
                <Separator/>
                <MenuItem Header="Close" Command="{Binding ActiveDocument.CloseCommand}"/>
            </MenuItem>
            <MenuItem Header="Tools">
                <MenuItem Header="Properties" IsChecked="{Binding FileStats.IsVisible, Mode=TwoWay}" IsCheckable="True"/>
            </MenuItem>
            <MenuItem Header="Layout">
                <MenuItem Header="Load" Command="{Binding LoadLayoutCommand, ElementName=mainWindow}"/>
                <MenuItem Header="Save" Command="{Binding SaveLayoutCommand, ElementName=mainWindow}"/>
                <MenuItem Header="Dump to Console" Click="OnDumpToConsole"/>
            </MenuItem>
        </Menu>
    </UserControl>

    How I am binding:

    public ViewC(IViewModel viewModel)
    {
       InitializeComponent();
       this.DataContext = Workspace.This;
    }

    and ViewModel:

    public class Workspace:ViewModelBase
    {
       FileStatsViewModel _fileStats = null;
       public FileStatsViewModel FileStats
       {
          get
            {
              if (_fileStats == null)
                 _fileStats = new FileStatsViewModel();
               return _fileStats;
            }
       }
    
       RelayCommand _newCommand = null;
        public ICommand NewCommand
        {
            get
            {
                if (_newCommand == null)
                {
                    _newCommand = new RelayCommand((p) => OnNew(p), (p) => CanNew(p));
                }
    
                return _newCommand;
            }
        }
    
        private bool CanNew(object parameter)
        {
            return true;
        }
    
        private void OnNew(object parameter)
        {
            _files.Add(new FileViewModel());
            ActiveDocument = _files.Last();
        }
    
    
       protected Workspace()
        { 
    
        }
    
        static Workspace _this = new Workspace();
    
        public static Workspace This
        {
            get { return _this; }
        } 
    }

    FileStatsViewModel:

    public class FileStatsViewModel : ToolViewModel {  }
    public class ToolViewModel
    {
        private bool _isVisible = true;
        public bool IsVisible
        {
            get { return _isVisible; }
            set
            {
                if (_isVisible != value)
                {
                    _isVisible = value;
                    RaisePropertyChanged("IsVisible");
                }
            }
         }
    }

    However, It does not work in Prism. I’ve tried setting some break point to check if the property is fired and FileStats property is firing in simple MVVM application, but FileStats property is not firing in Prism application! The code where I initialize my View:

    public class ModuleCModule: ModuleBase
    {
        public ModuleCModule(IUnityContainer container, IRegionManager regionManager)
                : base(container, regionManager) { }
    
        protected override void InitializeModule()
        {
            RegionManager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(ViewC));
        }
    
        protected override void RegisterTypes()
        {
            Container.RegisterTypeForNavigation<ViewC>();
        }
    }

    It is really interesting that I can fire my command <MenuItem Header="New" Command="{Binding NewCommand}"/>. However, I cannot fire property FileStats at viewModel Workspace.

    How to fire my property? What am I doing wrong?

    Imported from legacy forums. Posted by Stepan (had 181 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    We will need a complete sample that can compile in order to debug exactly what you have. Also, please specify how you fire the FileStats property in the application and what you expect when that property is fired.

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 71 views)

    User (Old forums)
    Member
    Post count: 23064

    [quote user=”Fawzi [Xceed]”]Hi,

    We will need a complete sample that can compile in order to debug exactly what you have. Also, please specify how you fire the FileStats property in the application and what you expect when that property is fired.[/quote]

    Hi! Thanks for the answer!  The Master Brian Lagunas helped me to find an error in my project. I’ve made a really rough error and the program says to me that:

    IOException was unhalded 

    Cannot locate resource images/property-blue.png’.
    However, I run and run my program and it works without this piece of xaml:

    <avalonDock:DockingManager.LayoutItemTemplateSelector>

                    <local:PanesTemplateSelector>

                        <local:PanesTemplateSelector.FileViewTemplate>

                            <DataTemplate>

                                <TextBox Text=”{Binding TextContent, UpdateSourceTrigger=PropertyChanged}”/>

                            </DataTemplate>

                        </local:PanesTemplateSelector.FileViewTemplate>

                        <local:PanesTemplateSelector.FileStatsViewTemplate>

                            <DataTemplate>

                                <StackPanel Orientation=”Vertical”>

                                    <TextBlock Text=”{Binding FileSize}”/>

                                    <TextBlock Text=”{Binding LastModified}”/>

                                    <TextBox Text=”test”/>

                                    <TreeViewItem Header=”—Level 1″ />                                                                  

                                </StackPanel>

                            </DataTemplate>

                        </local:PanesTemplateSelector.FileStatsViewTemplate>

                    </local:PanesTemplateSelector>

     

                </avalonDock:DockingManager.LayoutItemTemplateSelector>

     

    Brian Lagunas said that I should comment this code and the program will work:

    public FileStatsViewModel()

                : base(“File Stats”)

            {

                Workspace.This.ActiveDocumentChanged += new EventHandler(OnActiveDocumentChanged);

                ContentId = ToolContentId;

                /*BitmapImage bi = new BitmapImage();

                bi.BeginInit();

                bi.UriSource = new Uri(“pack://application:,,/Images/property-blue.png”);

                bi.EndInit();

                IconSource = bi;*/

            }

    And it really started to work! Thank you guys for cool library! 🙂

     

     

     

    Imported from legacy forums. Posted by Stepan (had 151 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.