public void Should_Apply_Data_Template_Binding_When_No_Template_Is_Set()
        {
            var view = new ExampleView();

            Assert.NotNull(view.List.ItemTemplate);
            Assert.IsType <FuncDataTemplate <object> >(view.List.ItemTemplate);
        }
        public void Should_Resolve_And_Embedd_Appropriate_View_Model()
        {
            var view = new ExampleView();
            var root = new TestRoot {
                Child = view
            };

            view.ViewModel.Items.Add(new NestedViewModel());

            view.List.Template = GetTemplate();
            view.List.ApplyTemplate();
            view.List.Presenter.ApplyTemplate();

            var child     = view.List.Presenter.Panel.Children[0];
            var container = (ContentPresenter)child;

            container.UpdateChild();

            var host = (ViewModelViewHost)container.Child;

            Assert.IsType <NestedViewModel>(host.ViewModel);
            Assert.IsType <NestedViewModel>(host.DataContext);

            host.DataContext = "changed context";
            Assert.IsType <string>(host.ViewModel);
            Assert.IsType <string>(host.DataContext);
        }
        public void Should_Not_Override_Data_Template_Binding_When_Item_Template_Is_Set()
        {
            var view = new ExampleView(control => control.ItemTemplate = GetItemTemplate());

            Assert.NotNull(view.List.ItemTemplate);
            Assert.IsType <FuncDataTemplate <TextBlock> >(view.List.ItemTemplate);
        }
        public void Should_Use_ViewModelViewHost_As_Data_Template_By_Default()
        {
            var view = new ExampleView();

            view.ViewModel.Items.Add(new NestedViewModel());

            var child     = view.List.Presenter.Panel.Children[0];
            var container = (ContentPresenter)child;

            container.UpdateChild();

            Assert.IsType <ViewModelViewHost>(container.Child);
        }
        public void Should_Not_Use_View_Model_View_Host_When_Data_Templates_Are_Not_Empty()
        {
            var view = new ExampleView(control => control.DataTemplates.Add(GetItemTemplate()));

            view.ViewModel.Items.Add(new NestedViewModel());

            var child     = view.List.Presenter.Panel.Children[0];
            var container = (ContentPresenter)child;

            container.UpdateChild();

            Assert.IsType <TextBlock>(container.Child);
        }
Beispiel #6
0
        public void Data_Context_Should_Stay_In_Sync_With_Reactive_User_Control_View_Model()
        {
            var view      = new ExampleView();
            var viewModel = new ExampleViewModel();

            Assert.Null(view.ViewModel);

            view.DataContext = viewModel;
            Assert.Equal(view.ViewModel, viewModel);
            Assert.Equal(view.DataContext, viewModel);

            view.DataContext = null;
            Assert.Null(view.ViewModel);
            Assert.Null(view.DataContext);
        }
Beispiel #7
0
        public void ViewModelPropertyTest()
        {
            var exampleViewModel = new ExampleViewModel();
            var exampleView      = new ExampleView();

            var viewManagerMock = new Mock <IViewManager>();

            viewManagerMock.Setup(vm => vm.GetViewFor(exampleViewModel)).Returns(exampleView).Verifiable();
            Binder.ViewManager = viewManagerMock.Object;

            var viewContainer = new ContentControl();

            Binder.SetViewModel(viewContainer, exampleViewModel);

            Assert.AreSame(exampleView, viewContainer.Content);
            viewManagerMock.VerifyAll();
        }
        public FileSelectionTextBoxExample()
        {
            InitializeComponent();

            ExampleView.AddDemoProperty(FileSelectionTextbox.AcceptsFileDropProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.HeightProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.WidthProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.HorizontalAlignmentProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.VerticalAlignmentProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.ForegroundProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.BackgroundProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.VisibilityProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.BorderThicknessProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.BorderBrushProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.FilterProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.TextProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(FileSelectionTextbox.IsReadOnlyProperty, fileSelectionTextBox);
            ExampleView.AddDemoProperty(TextBoxHelper.ClearTextButtonProperty, fileSelectionTextBox);
        }
Beispiel #9
0
        static void Main()
        {
            var example = new Example
            {
                num   = 42,
                str   = "test",
                items = { 3.14, 0 }
            };

            var output = new OutputBuffer();
            var writer = new CompactBinaryWriter <OutputBuffer>(output);

            Marshal.To(writer, example);

            var         input = new InputBuffer(output.Data);
            ExampleView view  = Unmarshal <ExampleView> .From(input);

            Debug.Assert(example.num == view.num);
            Debug.Assert(example.str.Equals(view.str, StringComparison.Ordinal));
        }
Beispiel #10
0
    /// <summary>
    /// Set up the GUI.
    /// </summary>
    private void SetUpGUI()
    {
        // First, create an instance of the view we want to bind the GUI to
        var viewModel = new ExampleView();

        // Set up the GUI widgets
        gui = new UnityEditorUI.GUI();
        gui.Root()
        .Label()
        .Text.Value("My new editor window")
        .End()
        .Button()
        .Text.Value("Do something!")
        .Click.Bind(() => viewModel.DoSomething())
        .Tooltip.Value("Click to trigger an event")
        .End();

        // Bind the resulting GUI to the view.
        gui.BindViewModel(viewModel);
    }
Beispiel #11
0
        private void InitializeComponent()
        {
            view                 = new ExampleView();
            view.Click          += OnExampleViewClick;
            view.GetTime        += OnExampleViewGetTime;
            view.ConstantMessage = "This is an example";
            view.Image           = ImageKind.Beach;
            view.ViewMounted    += OnViewMounted;
            view.InputChanged   += View_InputChanged;
            view.WithPlugin <ViewPlugin>().NotifyViewLoaded += OnNotifyViewLoaded;

            view.CustomResourceRequested += OnViewResourceRequested;

            childView = (SubExampleViewModule)view.SubView;
            childView.ConstantMessage          = "This is a sub view";
            childView.GetTime                 += () => DateTime.Now.AddHours(1).ToLongTimeString();
            childView.CustomResourceRequested += OnInnerViewResourceRequested;
            childView.WithPlugin <ViewPlugin>().NotifyViewLoaded += (viewName) => AppendLog($"On sub view loaded: {viewName}");
            childView.CallMe();
            childView.Load();
        }
Beispiel #12
0
    /// <summary>
    /// Set up the GUI.
    /// </summary>
    private void SetUpGUI()
    {
        // First, create an instance of the view we want to bind the GUI to
        var viewModel = new ExampleView();

        // Set up the GUI widgets
        gui = new UnityEditorUI.GUI();
        gui.Root()
        .Label()
        .Text.Value("Object movement tool")
        .Bold.Value(true)
        .End()
        .HorizontalLayout()
        .Label()
        .Text.Value("Object to look for")
        .End()
        .TextBox()
        .Text.Bind(() => viewModel.SelectedObjectName)
        .End()
        .End()
        .Vector3Field()
        .Label.Value("Position")
        .Vector.Bind(() => viewModel.ObjectPosition)
        .End()
        .Button()
        .Text.Value("Capture position")
        .Click.Bind(() => viewModel.CaptureObjectPosition())
        .End()
        .Button()
        .Text.Value("Set position")
        .Click.Bind(() => viewModel.SetObjectPosition())
        .End();

        // Bind the resulting GUI to the view.
        gui.BindViewModel(viewModel);
    }
Beispiel #13
0
        public ColorPickerSample()
        {
            InitializeComponent();

            ExampleView.AddDemoProperty(ColorPicker.SelectedColorProperty, colorPicker);
        }
Beispiel #14
0
 public MainViewModel()
 {
     CurrentView = new ExampleView();
 }
        public FileSelectionTextBoxExample()
        {
            InitializeComponent();

            ExampleView.GetAllProperties(fileSelectionTextBox);
        }