{"action":"closed","issue":{"url":"https://api.github.com/repos/reactiveui/ReactiveUI/issues/908","labels_url":"https://api.github.com/repos/reactiveui/ReactiveUI/issues/908/labels{/name}","comments_url":"https://api.github.com/repos/reactiveui/ReactiveUI/issues/908/comments","events_url":"https://api.github.com/repos/reactiveui/ReactiveUI/issues/908/events","html_url":"https://github.com/reactiveui/ReactiveUI/issues/908","id":97582719,"number":908,"title":"RoutingState.NavigateCommandFor extension produces command that cannot execute","user":{"login":"patsissons","id":5505280,"avatar_url":"https://avatars.githubusercontent.com/u/5505280?v=3","gravatar_id":"","url":"https://api.github.com/users/patsissons","html_url":"https://github.com/patsissons","followers_url":"https://api.github.com/users/patsissons/followers","following_url":"https://api.github.com/users/patsissons/following{/other_user}","gists_url":"https://api.github.com/users/patsissons/gists{/gist_id}","starred_url":"https://api.github.com/users/patsissons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patsissons/subscriptions","organizations_url":"https://api.github.com/users/patsissons/orgs","repos_url":"https://api.github.com/users/patsissons/repos","events_url":"https://api.github.com/users/patsissons/events{/privacy}","received_events_url":"https://api.github.com/users/patsissons/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/reactiveui/ReactiveUI/labels/investigate","name":"investigate","color":"fbca04"},{"url":"https://api.github.com/repos/reactiveui/ReactiveUI/labels/rxui","name":"rxui","color":"fef2c0"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-28T00:04:54Z","updated_at":"2016-01-11T10:38:17Z","closed_at":"2016-01-11T10:38:17Z","body":"Basically the issue is that when creating a reactive command using `RoutingState.NavigateCommandFor<T>()` the resulting command does not publish its `CanExecute` state immediately. Internally this might be a bug with `ReactiveCommand` (it's a bit hard for me to follow exactly why there is no initial published state). If it is not a bug in `ReactiveCommand` then `NavigateCommandFor` needs to be adjusted to seed the initial `CanExecute` state.\r\n\r\nBelow is an extremely minimal example of `NavigateCommandFor` failing.\r\n\r\n```csharp\r\n    public partial class MainWindow : Window\r\n    {\r\n        class TestViewModel : ReactiveObject, IRoutableViewModel\r\n        {\r\n            public IScreen HostScreen { get { throw new NotImplementedException(); } }\r\n            public string UrlPathSegment { get { throw new NotImplementedException(); } }\r\n        }\r\n\r\n        public MainWindow()\r\n        {\r\n            InitializeComponent();\r\n\r\n            // view components\r\n            var panel = new DockPanel();\r\n            var viewHost = new RoutedViewHost() { DefaultContent = \"No Content Loaded\" };\r\n            var button = new Button() { FontSize = 20, Content = \"Navigate\" };\r\n\r\n            // view layout\r\n            panel.Children.Add(button);\r\n            panel.Children.Add(viewHost);\r\n            DockPanel.SetDock(button, Dock.Bottom);\r\n            AddChild(panel);\r\n\r\n            // view model components\r\n            var router = new RoutingState();\r\n            var cmd = router.NavigateCommandFor<TestViewModel>();\r\n\r\n            // this will seed the CanExecute state\r\n            //cmd.CanExecuteObservable.Subscribe();\r\n\r\n            // bindings\r\n            viewHost.Router = router;\r\n            button.Command = cmd;\r\n        }\r\n    }\r\n```\r\n\r\nIn this example we would expect that the button can be executed upon loading the UI. However, the button remains disabled due to the `CanExecuteObservable` failing to publish the initial state. We can *force* the initial state by uncommenting the line and subscribing to the observable (note that this must be run before *binding* the command to the button (I'm not really binding, but it is essentially the same).\r\n\r\nThe best solution I have come up with so far is to create a new extension method to patch this behaviour:\r\n\r\n```csharp\r\n    public static class ExtensionMethods\r\n    {\r\n        public static IReactiveCommand PatchedNavigateCommandFor<T>(this RoutingState This)\r\n            where T : IRoutableViewModel, new()\r\n        {\r\n            var ret = new ReactiveCommand<object>(This.Navigate.CanExecuteObservable.Skip(1), x => Observable.Return(x));\r\n            ret.Select(_ => (IRoutableViewModel)Locator.Current.GetService<T>() ?? new T()).InvokeCommand(This.Navigate);\r\n\r\n            return ret;\r\n        }\r\n    }\r\n```\r\n\r\nThe `Skip(1)` allows for a simple inline seeding of the initial `CanExecute` state."}}